nohupのforループ

nohupのforループ

8つのforループを同時に実行するbashスクリプトを実行しようとしています。

以下のforループの1つ

for i in 00 01 02 03 04 ; do cat $INDIR/sys*$1.$i*csv | \ 
awk -F '\xac' 'BEGIN{OFS=";";} ($4 == 10)  { $1=$1; print }'> $OUTDIR/$1_$i.csv

だから私は次の構文に変換して実行しました。nohup

nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv| \
awk -F \'\\xac\' \'BEGIN{OFS=\";\";} ($4==10) { $1=$1; print }\'>$OUTDIR/$i.csv;done' &

しかし、次のエラーが発生します

test.sh: line 9: syntax error near unexpected token `('
test.sh: line 9: `nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F \'\\xac\' \'BEGIN{OFS=\";\";} ($4==10) { $1=$1; print }\'>$OUTDIR/$i.csv;done' & '

私も次のコードを変更しようとしました。

nohup sh -c '<code>'
nohup /bin/bash -c '<code>'
\'\xac\'

しかし、何の進展もありませんでした。

しかし、私のforループはnohup

ベストアンサー1

コードを2つのスクリプトに分割する方が簡単です(読み取り:読みやすく保つのが簡単です)。 1つは実際の関数を実行し、もう1つは実行します。後者のサンプルコード:

for i in 00 01 02 03 04; do
    nohup /path/to/workerScript.sh ${i}
done

ロジックを単一のスクリプトとして保持したい場合でも、次の方法を使用できます。

if [ $# -eq 0 ]; then
    for i in 00 01 02 03 04; do
        nohup $0 ${i}
    done

    exit 0
fi

# Rest of the logic follows

おすすめ記事