我有一段代码如下:
# 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
变量是对存在的文本文件或文件夹的引用。
据我所知, ( ) 创建了一个子shell。这是否意味着括号中的所有内容都在不同的进程中运行?这会对性能产生什么影响?我应该注意哪些其他差异或陷阱?
PS:如果有人可以将标题编辑为更“搜索友好”,我将不胜感激。这是我能想到的最好的描述。