0

I have got a section of shell script which was working earlier but now it is giving some different results:

MSG=

 while  true
 do
    themenu
    getchar =

   case $answer in
       1) export_Config_tables;;
       2) export_config_tables_file;;
       3) export_Accounts_tables;;
       4) export_both_tables;;
       5) load_config_tables;;
       6) load_config_tables_file;;
      x|X) break;;
    q|Q) break;;
    d|D) toggle_debug;;
         *) badchoice;;

   esac
  done
clear

the menu function:

themenu () {
clear
echo `date `
echo
echo " summit Data Extract utility   (SOPRA v1.1)"
echo
 echo
 echo  "1.  Extract summit configuration data only"    
 echo  "2.  Extract summit config data in flat files only"
 echo  "3.  Extract summit account data only"
 echo  "4.  Extract all data "
 echo  "5.  Load summit configuration data from Dump"    
 echo  "6.  Load summit config data from flat files only"
 echo
 echo
 echo  "x.  Exit"
 echo
 echo $MSG
 echo
 echo "Select option : ";
 }

the getchar function:

getchar (){
        stty raw
    answer=`dd bs=1 count=1 2> /dev/null `
    stty -raw
}   

the bad choice function:

badchoice () {
 MSG="Invalid menu choice"
}

After executing the script, it displays the menu

<System date>

summit Data Extract utility   (SOPRA v1.1)


1.  Extract summit configuration data only    
 2.  Extract summit config data in flat files only
 3.  Extract summit account data only
 4.  Extract all data 
 5.  Load summit configuration data from Dump
 6.  Load summit config data from flat files only


 x.  Exit

 Select option : 

User inputs 5, but it doesn't display on the screen and after pressing Enter 2-3 times, it displays the message:

Invalid menu choice.

I am unable to figure out where it is causing problem. The menu function executes fine, it causes problem when it enters getchar() function and the case statement.

  • 1
    Hi Biswajeet. Is there a reason to use the getchar function instead of just the read builtin? Make sure you have some spaces where they need to be. "getchar () {" and comment out the function separators "#------- the getchar function ----". – kevlinux Jun 2 at 7:50
0

Didn't work for me as written, presumably because

answer=`dd bs=1 count=1 2> /dev/null `

doesn't execute the command and set answer to the return value of dd but rather assigns the string (dd bs=1 count=1) to the variable answer.

Editing to give the expansion

answer=$(dd bs=1 count=1 2> /dev/null)

worked fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.