开发者

multiple line command and status code

sfdisk -D $val << EOF
,,$type  
EOF

How can I check its status af开发者_运维百科ter execution? Not via if...$?, but by disjunction ||. What I mean is I can do the folllowing: ls || exit 4 It will exit with code 4 if ls encountered error, but how can I do it in my example?

And the second question is, how can I perform multiple commands on failure? Is something like this Ok?

`ls` || { echo "!!!"; exit 4 }

Thank you!


You're actually asking two different questions...

The answer to the first, is that you put the conditions after the << FOO part:

I'm using && here for convience to see the output. But with this command set:

# cat << EOF && ( echo hi ; echo there )
foo
bar
EOF

You get:

foo
bar
hi
there

Answering your second question, you should use ()s:

# bash -c 'exit 1' || ( echo hi ; echo there )
hi
there
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜