开发者

How to write command in bash?

How to write command in bash ? ( for user test if pro开发者_运维百科gram return segmentation fault, remove lock file. )

su -c "/usr/local/bin/test || if $? > 0 then rm -fr /var/run/test.lock " test


$? in double quotas is expanded before su command is executed.

You don't need to check $? - right part of || is executed only if test fails:

su -c "/usr/local/bin/test || rm -fr /var/run/test.lock " test


su -c "/usr/local/bin/test || if [ $? -gt 0 ]; then rm -fr /var/run/test.lock; fi" test

or

su -c "/usr/local/bin/test || [ $? -gt 0 ] && rm -fr /var/run/test.lock" test
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜