次のようなコードがあります。
# step through the jobs and execute them one by one
while IFS= read -r job
do
[ -n "$job" ] && (
script=$JOBDIR/$job.sh
( [ -x $script ] && /bin/sh $script ) || echo `date +%Y-%m-%d` `date +%H:%M:%S` "$script does not exist" >> $JOBFAILS
)
done < $JOBLIST
これは(AFAIK)次のように書くこともできます:
# step through the jobs and execute them one by one
while IFS= read -r job
do
if [ -n "$job" ] then
script=$JOBDIR/$job.sh
if [ -x $script ] then
/bin/sh $script || echo `date +%Y-%m-%d` `date +%H:%M:%S` "$script does not exist" >> $JOBFAILS
fi
fi
done < $JOBLIST
変数は、存在するテキスト ファイルまたはフォルダーへの参照です。
私の知る限り、() はサブシェルを作成します。これは、括弧内のすべてが別のプロセスで実行されるということですか? そのことによるパフォーマンスへの影響はどのようなものでしょうか? 他に知っておくべき相違点や落とし穴はありますか?
PS: タイトルをもっと「検索しやすい」ように編集していただけると助かります。それは私が思いつくことができる最高の説明です。