Command substitution, or Inline Execution as I call it, $()
in Bash allows for text returns; before the execution of a main command. How do I abort the main command, if a $() returns an error code
More specifically I want to stop/prevent a secondary Inline Execution from being attempted.
Echo $(ls /devb/*) is better than $(ls /dev/*)
i.e. if "ls /devb/" returns a non-zero exit code, I don't want to run a listing of /dev,
My real example gets to be rather wordy, and the specifics aren't super important to the question, but a simplified version is
Connect_to_foreign_system 1.1.1.1 /u:$(zenity <prompt for user>) /p:$(zenity <prompt for password>)
If the prompt for user is canceled, zenity returns with a exit code of 1, but the main command continues, and then prompts for a password.
If the first prompt errors I really don't want to prompt for the password, and it would be nice to not run Connect_to_foreign_system.
I'm not running this in a script, this is pure command-line, but even if I put it in a script with set -e
both the second inline and main command, still runs anyway.
I know that I can write a script to get each text string and then run the command and test for exit-codes as I go. I'm asking how to do it as a standalone statement.