I want to call the unix dialog
editbox from within a generic function in bash. The two outcomes I am interested in are:
- If the user hits OK I would like to capture what the user has entered into the editbox
- Detect if the user hits Cancel
Here is some code I have but I'm not sure if this is the best way:
function ib_generic()
{
tmp_file="/tmp/file.tmp"
if [ -f $tmp_file ]
then
rm -f $tmp_file
fi
mkfifo $tmp_file
# push the user input to $tmp_file
dialog --stdout \
--title "$1" \
--backtitle "My Backtitle" \
--inputbox "$2" 20 40 2> $tmp_file &
# detect 'cancel' or 'escape':
if [[ $? -eq 0 || $? -eq 255 ]]
then
rm -f $tmp_file
echo 1
else # 'ok' was pressed so proceed:
result="$( cat /tmp/file.tmp )"
rm -f $tmp_file
echo $result
fi
}
What's the best way to cancel the result if OK is hit and if not, how to detect Cancel or Escape?