Case execution problem

hi guys....in my code the echo statements inside case statements are not printing the required display info....pls help me out

#!/bin/bash
tput clear
tput cup 3 15
tput setaf 3
echo "BACKUP PROJECT"
tput sgr0
tput cup 5 17
tput rev
echo "select option"
tput sgr0
tput cup 7 15
echo "1.auto Backup"

tput cup 8 15
echo "2.manual Backup"

tput bold
tput cup 12 15

read -p "Enter your choice [1-2]:" choice
case $choice in

1) echo "autobackup" ;;
2) _zenity="/usr/bin/zenity"
 SOUR_PATH=$(${_zenity} --title "Enter source path"\
                        --entry --text "Enter the source pathe to backup" )
tput clear
tput setaf 3
tput cup 5 17
tput rev
echo "Select Destination"
tput sgr0
tput cup 7 15
echo "3.local"

tput cup 8 15
echo "4.Remote"

tput bold
tput cup 12 15

read -p "Enter choice:" choic
case $choic in

3) echo "local destinaion";;
4) echo "remote destintion";;
esac
;;
esac

A couple of possible problems here. The last two lines

;;
esac

... are unnecessary.

The read -p is trying to read from a pipe, not from the screen. If this were ksh I would suggest changing it to say:-

read choice?"Enter choice:"
case $choice in
   3) echo "local destination"     ;;
   4) echo "remote destination"    ;;
   *) echo "unknown destination"  ;;
esac

... but I'm not sure what bash willl support or if my suggesting is superseded by better bash coding.

I hope that this helps,
Robin
Liverpool/Blackburn
UK

Thread moved to shell... Do not post in Contact admins!

Sorry it did not solve my problem.....and

read -p

is required to read from tput

What is the issue? Or what is not printed? But the best would be you explain what it should display...

when a choice is provided....the echo statement for that particular choice is not executing.

Funny it seem to work here...

               BACKUP PROJECT

                 select option

               1.auto Backup
               2.manual Backup



               Enter your choice [1-2]:1
autobackup

If I enter 2:

                 Select Destination

               3.local
               4.Remote



               Enter choice:3
local destinaion

Same here. Try inserting set -x at the second line after the shebang to get some more debugging info

when i executed the code without nested case i got the required output....but when i included nested case none of the echo statement is printing

Works for me as well (bash 4.2.24).

As Subbeh suggested, turn on tracing and post the output (and your script, if you've changed it).

For the bash builtin, -p <text> just writes <text> to stderr before it waits for input.

1 Like

Thank u guys....got it now.,

read -p Shows the message to the user that is passed after -p ...

Further, the trailing

;;
esac

should be moved to the end of the first case..

read -p "Enter your choice [1-2]:" choice
case $choice in

1) echo "autobackup" ;;
2) _zenity="/usr/bin/zenity"
 SOUR_PATH=$(${_zenity} --title "Enter source path"\
                        --entry --text "Enter the source pathe to backup" )

hth