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
精彩评论