Solved Bash if variable blank quit or restart input

January 23, 2014 at 05:26:42
Specs: Macintosh , 2GB
Hi, I'm trying to figure out how to make this work. I've got the code all jumbled up trying to make things work and it's now just a mess. If you don't input anything, it assumes you're trying to quit, asks you if you want to quit, if no then reasks the question.

CAPTION=`zenity --entry --title="New Desktop Icon" --text="Enter the icon name as you want to appear on the desktop."`

if [ -z "$CAPTION" ]
then
if $QUIT=0
then
end
else
CAPTION=`zenity --entry --title="New Desktop Icon" --text="Enter the icon name as you want to appear on the desktop."`
fi


See More: Bash if variable blank quit or restart input

Report •

#1
January 23, 2014 at 12:45:51
✔ Best Answer
I am not certain how your shell variable QUIT is being set so I am making some assumptions. One way is to place the zenity call into a while loop and continue the loop until valid input is received. Let me know if you have any questions:

#!/bin/bash

while [ 1 ]
do
   CAPTION=`zenity --entry --title="New Desktop Icon" --text="Enter the icon name as you want to appear on the desktop. type QUIT to end"`
   if [ -z $CAPTION ]
   then
      continue
   else
      break
   fi
done
if [ $CAPTION == "QUIT" ]
then
   echo "QUITTING"
   exit
fi


message edited by nails


Report •
Related Solutions


Ask Question