Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BASH scripting - menu dialog

Posted on 2007-04-02
6
Medium Priority
?
8,959 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 2000 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

618 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