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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In most cases this will do:
The corner case is, thanks to @uzsolt, when
touch completeitself can fail. Thentouch failedis executed. In case the difference matters, you can use this one: