shell - Cause bash statement to error if its subshell errors -


is there concise, general, idiomatic bash construction force statement error when subshell invokes errors? example,

cd $(git rev-parse --show-toplevel) 

will invariably return 0 if git command errors, makes difficult script like

cd $(git rev-parse --show-toplevel) && echo 'success!' 

of course can following, wondering if there better way:

dir=$(git rev-parse --show-toplevel) && cd $dir && echo 'success!' 

it's not quite general solution, in example do:

cd $(git rev-parse --show-toplevel || echo -@) && echo 'success!' 

this solution works turns output command won't accept if command in substitution fails.


Comments

Popular posts from this blog

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

javascript - Create websocket without connecting -

sharepoint - Accessing files across a shared directory using a Windows service -