bash - Assign command output to a variable and do if branch on the return value -


i want following thing

x=$(some_command) if [ $? == 0 ];   do_something   echo $x else   do_something_else fi 

basically, want execute command, store output variable. meanwhile, want branch based on whether command succeeded or not. above way works, looks ugly. smarter way?

thanks.

if x=$(some command);   do_something   echo $x else   do_something_else fi 

the if command works running command , testing whether successful, , executing then or else branch depending on it.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -