Solved

BASH scripting - menu dialog

Posted on 2007-04-02
6
8,915 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

13 Experts available now in Live!

Get 1:1 Help Now