Script logic from bash command replacement

I have the following snippet in my script:

exec 3<<<"$(zenity --entry --title="Enter PIN" | validate_pin || error_handler )"

      

Elsewhere I have to pass the PIN through the file descriptor, hence command remapping and substitution will be here.

The withdrawal validate_pin

is the modified value of the entered PIN, but the exit code determines if it was successful and valid. What can you put in error_handler

to handle any failures?

If I have exit

, it comes out of the command substitution subheading. Assigned variables ( FAIL=1

etc.) are also destroyed as soon as the command substitution sub-header is closed. Reading a file descriptor to check if it works, but then it closes and the subsequent process cannot use it.

+3


source to share


1 answer


The best way I've found so far is to use a temporary file.



exec 3<<<"$(zenity --entry --title="Enter PIN" | validate_pin || touch .fail )"
if [[ -f .fail ]] ; then
    do_stuff
fi

      

+1


source







All Articles