Select Command - return | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Select Command - return

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-05-2013
gio001 gio001 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 29 March 2014, 10:33 AM EDT
Posts: 117
Thanks: 8
Thanked 1 Time in 1 Post
Select Command - return

Hello everyone,
A simple question which may have a suggested solution:
I am using, and loving, the select command in a ksh93 script on AIX 6.1 to present users with menus.
I have been successful in controlling all of key input by the users, I still have an issue with the RETURN key. When the menu is presented if the user presses the return key by itself the menu gets redrawn. If the user keeps pressing return the screen keeps getting full of the same menu over and over and it scrolls.
Is there a way to capture the fact that return was pressed by itself and take care of action needed in the do....done attached to the select?
Or alternatively allow the return to redraw the menu but on top the original one, and not append it to the screen after the PS3 prompt?
Hope you all have some suggestions.
Thanks, and a Happy New Year everyone !
Sponsored Links
    #2  
Old 01-05-2013
spacebar's Avatar
spacebar spacebar is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 2 June 2014, 3:23 PM EDT
Location: spaceBAR Central
Posts: 440
Thanks: 0
Thanked 70 Times in 70 Posts
This is a simple menu script I put together that might help you accomplish what your trying to do, It doesn't require the user to press return and it stays at top of screen:


Code:
#!/usr/bin/ksh
# Script: example_menu.sh
# Descr:  Example of auto record advance(i.e. carriage return) with simple menu

function _choices
{ clear
  cat <<BOX

     HANDY INFO - Choose Desired Number
     ====================================
  1  Current Directory
  2  Your Login ID
  3  UNIX Processes for your ID
  4  Entry in /etc/passwd for your ID
  5  Users with ID of 0 (zero)
  6  Users with ID >= 500
  7  ID Search PATH for $LOGNAME
  8  Currently Mounted devices
  9  HD Usage and mount-points

  0  Exit

BOX
} # EOF  _choices()


function _action
{
  stty raw
  ans=`dd bs=1 count=1 2>/dev/null`
  eval $1='$ans'
  stty cooked
} # EOF  _action()


function _complog
{ # Required argument: $1 = output of logname command
  if [[ "${1}" != "${LOGNAME}" ]]
  then
    echo "\bYour Login ID is: \"${1}\" (real) and \"${LOGNAME}\" (su)."
  else
    echo "\bYour Login ID is: \"${1}\"."
  fi
} # EOF  _complog


function _waiter
{ echo "\nPress <Enter> to continue.... \c"
  read waiting4u
} # EOF  _waiter()


function _yourc
{
  case "${ans}" in  # process response
    1) echo "\bThe current directory is: \c"; pwd; _waiter ;;
    2) _complog "${user}"; _waiter ;;
    3) echo "\b\b"; ps -ef | grep "${user}" | more ; _waiter ;;
    4) echo "\b\b"; grep "${user}" /etc/passwd; _waiter ;;
    5) echo "\b\b"; awk -F":" '$3 == 0 {print $0}' /etc/passwd; _waiter;;
    6) echo "\b\b"; awk -F":" '$3 >= 500 {print $0}' /etc/passwd | more ; _waiter;;
    7) echo "\b\b"; echo $PATH | awk 'BEGIN {RS=":"} {print $0}'; _waiter;;
    8) echo "\b\b"; mount | awk '$1 != "none" {print $0}'; _waiter;;
    9) echo "\b\b"; df; _waiter ;;
    0) clear; exit 0 ;;  # breaks the loop
    *) echo " Invalid option...." ; _waiter ;;
  esac
} # EOF  _yourc()


user=`logname`
while :
do
  _choices          # display the menu
  _action _yourc    # gather user response
  _yourc
done

Sponsored Links
    #3  
Old 01-07-2013
gary_w's Avatar
gary_w gary_w is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 10 April 2014, 2:21 PM EDT
Posts: 446
Thanks: 32
Thanked 96 Times in 88 Posts
Just issue a clear command right before displaying the menu. You may have to use tput clear .
    #4  
Old 01-08-2013
gio001 gio001 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 29 March 2014, 10:33 AM EDT
Posts: 117
Thanks: 8
Thanked 1 Time in 1 Post
I response to last comment: pressing return when select is in place does not give me back control, therefore I cannot issue a CLEAR.
Experiment yourself and you will see what I mean. How can I trap the return being pressed by itself?
Thanks
Sponsored Links
    #5  
Old 01-08-2013
binlib binlib is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 15 March 2013, 10:40 AM EDT
Location: New Jersey
Posts: 380
Thanks: 7
Thanked 90 Times in 75 Posts
Interesting problem. One ugly hack:

Code:
Q="$(clear)1) Quit"  
select c in "$Q" ...
do
  case $c in
  "$Q") break ;;
  ...
  esac 
done

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to use select into command in shell script? vel4ever Shell Programming and Scripting 16 12-23-2011 02:25 AM
::select statement return value with correct field size:: ryanW Shell Programming and Scripting 10 04-23-2009 02:38 AM
Select command to build menu gio001 Shell Programming and Scripting 1 08-30-2008 12:56 PM
Select command array gio001 Shell Programming and Scripting 2 08-05-2008 08:43 AM
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 06:44 AM



All times are GMT -4. The time now is 12:11 PM.