Solved

BASH scripting - menu dialog

Posted on 2007-04-02
6
8,945 Views
Last Modified: 2013-12-26
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 ?
0
Comment
Question by:rares_dumitrescu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18839075
what is $answer when it does not go to 'dialog --inputbox "What port do you wish for the psybnc ?" 07 40
' as it should
0
 
LVL 84

Expert Comment

by:ozo
ID: 18839186
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
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18839196
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rares_dumitrescu
ID: 18841343
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 ? :|
0
 
LVL 84

Expert Comment

by:ozo
ID: 18841356
where does it block?
exec 2> $tempfile
and
cat /dev/null > $tempfile
in the same script could confuse the buffers
0
 

Author Comment

by:rares_dumitrescu
ID: 18848894
i made it work, thanx for your response, it helped
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question