开发者

Create a file when the command succeed. Create another when it fails. One line?

In Bash, I want to create a file when the command succeed, otherwise create another file. Something along the 开发者_运维知识库line of

if `my command`; then
  touch command.complete
else
  touch command.fail
fi

Is it possible to write this in one line?


In most cases this will do:

my.command && touch command.complete || touch command.failed

The corner case is, thanks to @uzsolt, when touch complete itself can fail. Then touch failed is executed. In case the difference matters, you can use this one:

my.command && (touch command.complete || true) || touch command.failed
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜