Solved

BASH scripting - menu dialog

Posted on 2007-04-02
6
8,925 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now