2013-04-12 61 views

回答

3

外尝试写这样说:

test -f no_such_file || { ok='0'; echo ggg; } 

的{}会给你分组,但不会启动一个子shell。在这种情况下,& &没有用,所以我用';'替换了它。

2

原因是(ok='0' && echo ggg)在子外壳中运行,因为它包含在() s中。如果没有括号运行:

ok="1" 
test -f no_such_file || ok='0' && echo ggg 
> ggg 
echo $ok 
> 0 

你将不得不调整自己的逻辑离开赋值语句()小号

+0

谢谢亚历克斯,但你的回答产生了一个不正确的结果 - 无论no_such_file是否存在,echo ggg都会被执行 –