在bash中,我可以执行以下操作:
if [ -f /tmp/test.txt ]; then echo "true"; fi
但是,如果我sudo
在前面添加,它将不再起作用:
sudo if [ -f /tmp/test.txt ]; then echo "true"; fi
-bash: syntax error near unexpected token `then'
我该如何运作?
1
看到这样的答案 ...
—
jasonwryan 2012年
更好的做法是
—
jippie 2012年
sudo
仅test
和和/或仅echo
。不是整个if
陈述。
你的意思是
—
m33lky 2012年
if sudo test
?是的,那会更好。如果test
没有if
,我将无法使用,因为否则会设置退出代码。