Link to home
Start Free TrialLog in
Avatar of rares_dumitrescu
rares_dumitrescu

asked on

BASH scripting - menu dialog

Hello, i have a little problem with a script:
This is the code:
#!/bin/sh
tempfile=$$.tmp

exec 2> $tempfile
answer="xxx"

if [ -e psybnc ] ; then
dialog  --title "You are using the command - getpsy" \
        --inputbox "The directory psybnc exists, choose another" 8 50
newdir=`cat $tempfile`
cat /dev/null > $tempfile
if [ -e $newdir ] ; then
dialog --title "You are using the command - getpsy" \
       --msgbox "The directory $newdir also exists, begin the process again !" 5 50
rm -f $tempfile
exit 1
else
mkdir $newdir
cd $newdir
cat /dev/null > $tempfile
fi
fi

while [ "$answer" != "" ]; do
dialog --clear --title "Main Menu" \
        --menu "Use arrows to go up/down \n\
        [Enter] to select \n\
        Select one:" 20 40 10 \
        "1"       "Choose the psybnc port" \

answer=`cat $tempfile`
test "$answer" = "" && continue

if [ "$answer" = "1" ]; then
   cat /dev/null > $tempfile
   dialog --inputbox "What port do you wish for the psybnc ?" 07 40
   port=`cat $tempfile`
   echo "the port is '$port'" >psybnc.c
fi


cat /dev/null > $tempfile
done
rm -f $tempfile

When i press enter on the psybnc port the script stops, it does not go to 'dialog --inputbox "What port do you wish for the psybnc ?" 07 40
' as it should
Any ideeas ?
Avatar of ozo
ozo
Flag of United States of America image

what is $answer when it does not go to 'dialog --inputbox "What port do you wish for the psybnc ?" 07 40
' as it should
Did you try
dialog --clear --title "Main Menu" \
        --menu "Use arrows to go up/down \n\
        [Enter] to select \n\
        Select one:" 20 40 10 \
        "1"       "Choose the psybnc port" \ 2>$tempfile
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rares_dumitrescu
rares_dumitrescu

ASKER

i didnt have to put 2>$tempfile till now .. and no, with that it just blocks
something strange is happening

with out this:
if [ -e psybnc ] ; then
dialog  --title "You are using the command - getpsy" \
        --inputbox "The directory psybnc exists, choose another" 8 50
newdir=`cat $tempfile`
cat /dev/null > $tempfile
if [ -e $newdir ] ; then
dialog --title "You are using the command - getpsy" \
       --msgbox "The directory $newdir also exists, begin the process again !" 5 50
rm -f $tempfile
exit 1
else
mkdir $newdir
cd $newdir
cat /dev/null > $tempfile
fi
fi
the script works if i delete this, i mean the remaining code works:
#!/bin/sh
tempfile=$$.tmp

exec 2> $tempfile
answer="xxx"

while [ "$answer" != "" ]; do
dialog --clear --title "Main Menu" \
        --menu "Use arrows to go up/down \n\
        [Enter] to select \n\
        Alegeti program wishlist:" 20 40 10 \
        "1"       "Choose the psybnc port" \
        "2"       "Choose the psybnc language"\
        "3"       "Choose the psybnc's login at X"\
        "4"       "Choose the psybnc's password at X"\
        "5"       "Choose the psybnc's directory"\

answer=`cat $tempfile`
test "$answer" = "" && continue

if [ "$answer" = "1" ]; then
   dialog --inputbox "What port do you wish for the psybnc ?" 07 40
   port=`cat $tempfile`
   echo "the port is '$port'" >psybnc.c
fi

cat /dev/null > $tempfile
done

rm -f $tempfile


whats wrong in that if i wrote ? :|
where does it block?
exec 2> $tempfile
and
cat /dev/null > $tempfile
in the same script could confuse the buffers
i made it work, thanx for your response, it helped