【发布时间】:2013-05-09 00:12:51
【问题描述】:
cat list.txt | grep '^http://.*\.osm\..*$' | while read line; do
fn=$(basename $line)
do_something()
done
# TODO: check if it did something
如果 grep 命令不返回任何内容,它不会进入循环并且 do_something() 不会被执行。
我无法在 while 循环之外检查 $fn 中的内容,请参阅 Bash variable scope。
检查 do_something() 是否在此处执行的侵入性最小的解决方案是什么?
【问题讨论】:
-
为什么不在 do/done 中分配一个变量?
-
@klugerama 除非您使用
bash4.2 和lastpipe选项,否则在该循环内设置的变量在之后无法显示。
标签: bash