我有一个基本上看起来像这样的bash脚本:
for f in "mydirectory"/*; do
someprogram "$f"
if [ $? -ne 0 ]
then
echo "someprogram had an error on $f"
fi
done
它运行正常,但如果“someprogram”返回错误,我会收到以下消息:
someprogram had an error on
由于某种原因,在if语句中忘记了循环变量“f”。它是否正确?有办法解决这个问题吗?