Reputation: 15336
I would like to execute the following command ruby do_task.rb && say "done"
.
The problem is that it say nothing if the command failed. How to fix it so that it would always say something (I don't mind if it say "failed" instead of "done", or just always say "done").
Upvotes: 0
Views: 123
Reputation: 5006
Simply :
(ruby do_task.rb && say "done") || (say "fail")
Or as suggested by @LéaGris to avoid spawning subshells,
{ ruby do_task.rb && say "done";}||say "fail"
Or
ruby do_task.rb; say "end"
Upvotes: 4
Reputation: 19555
Another way using a message array (need shell with arrays) indexed with the return code.
message=('success' 'failure')
ruby do_task.rb
say "${message[$?]}"
Also note that if return code of ruby do_task.rb
is greater than 1, you will need an array with messages at indexes for each return codes.
To maintain a binary success or failure with the method above:
message=('success' 'failure')
ruby do_task.rb
say "${message[$(($?>0))]}"
Upvotes: 2
Reputation: 1963
Just replace && with a semicolon ;
ruby do_task.rb;say "done"
Upvotes: 6