1

I got some troubles when managing dialog output and exit codes. Essentially I'm trying to get a one-line script for getting dialog selection and terminate script function:

local _ui_envname=$(dialog --stdout --cancel-label "Back" --inputbox 'Enter the new environment name:' 0 0) || { echo "Failed"; exit 1; }

However the above command fails miserably (the { echo "Failed"; exit 1; } is not executed at all when dialog exit code is 1). The culprit seems to be the local keyword: removing the local variable specifier it starts working as expected.

What is going on? Am I doomed to use "global" variables?

1 Answer 1

1

Not only local, all declaration utilities mask the exit code of the substituted command, because the assignment does not fail.

The usual workaround is:

local _ui_envname
_ui_envname=$(dialog --stdout --cancel-label "Back" --inputbox 'Enter the new environment name:' 0 0) || { echo "Failed"; exit 1; }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.