Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Korne Shell Programming

Status
Not open for further replies.

fmuquartet

Programmer
Sep 21, 2006
60
US
Greetings,
Is there anyone who is a really good korne programmer that can help modify a korne shell to prompt the user if he/she are sure they want to run a menu selection?

Any help is kindly appreciated.
 
Here is a snippet from a script I wrote recently:

Code:
echo "Removing files from: $DEST"
YN=""
while [[ $YN != "yes" && $YN != "no" ]]
do
  echo "$ESC[12;01f$CLR_EOL$ESC[12;01fAre you ABSOLUTELY sure? (yes/no): \c"
  read YN
  YN=$(echo $YN|tr [:upper:] [:lower:])
done

Notes:

I used escape codes to:
- place the cursor at the desired row & column
- clear from row & column to end of line
- if looping back thru due to bad answer, want old answer erased.

It will only accept "yes" or "no" for an answer. The script will take appropriate action depending on the (correct) answer given.
 
sbrews, nice!

This is perfect, I suspect that I can easily modify an existing function to call this code. I will see if modify the function in question around your code does the job.

Again many thanks for your prompt response.
 
... here is a quick script I put together for handling menu items. Hope this helps with your script.

Code:
ESC="\033"                      # Escape
CLRSCR="\033[H\033[J"           # Clear screen, cursor to top of screen
CLREOL="\033[0K"                # Clear from cursor to end of line
#
echo "$CLRSCR"
echo "$ESC[03;05f1.) option 1"
echo "$ESC[04;05f2.) option 2"
echo "$ESC[05;05f3.) option 3"
echo ""
echo "$ESC[07;05fEnter choice <1-3>: \c"
CHOICE=""
while [[ $CHOICE != [1-3] ]]
do
  read CHOICE
  if [[ $CHOICE != [1-3] ]]
  then
    echo "$ESC[07;05fInvalid choice.  Please try again."
    sleep 2
    echo "$ESC[07;05f${CLREOL}Enter choice <1-3>: \c"
  fi
done
#
case $CHOICE in
     1) echo "Option 1 chosen"
        echo "do some option 1 stuff" ;;
     2) echo "Option 2 chosen"
        echo "do some option 2 stuff" ;;
     3) echo "Option 3 chosen"
        echo "do some option 3 stuff" ;;
esac
 
sbrews, I will see if I can incorporate some of this scripting logic into my existing script and see if things work!

Many Thanks!
 
Hi,

sbrews, using escapes may work on a kind of terminal but not working on others.
The best way is to use terminfo database capability by using [red]tput[/red] command:
Code:
tput clear      #clear terminal
tput smso       # set mode stand out ( reverse video in general )
tput rmso       # reset mode stand out
tput cup 10 20  #position cursor at line 10 column 20
tput el         # clear end of line
and more ...
man tput ; man terminfo for more
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top