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