Read with two values

I have a script like this:

read -e -r -p "enter name of product in CAPS:  " ITEM
echo -e "Please enter the product number"
read -e -r -p "Enter list at date:" list

#Here someone enters case6 for ITEM

if [[ $ITEM == case6 ]]; then ITEMLST=`echo CASESIX`;fi

Then I have commands that look for the directory CASESIX and retrieves files: This command uses $ITEMLIST as the variable

after that I want to be able to ssh to case6:.

for i in `cat /tmp/productlist`; do su ncacct -c "ssh $ITEM /usr/query -m $i""" |
gawk '{if ($3 == "TLD") print "product '$i' is in truck"}';done

The problem is that I want the user to be able to enter either case6 or CASESIX and have the script go to the directory CASESIX which value "ITEMLST" holds.

Right now they must enter case6 and then the variable will get translated to CASESIX for the directory CASESIX. after that the ssh command will use "case6" as the value and ssh to the host case6

Is there a way to do this other than to make someone enter case6 for the read command? I would like if someone could enter case6 or CASESIX in that read command somehow and have the last command know that it should use case6 to ssh. Maybe it is not possible?

Have you considered a case statement in your script? - not to be confused with them entering the word case6 or CASESIX

Something like:-

case "$ITEM" in
  case1|CASEONE)    # Do whatever case1 needs 
                 ;;
  case2|CASETWO)    # Do whatever case2 needs 
                 ;;
  case3|CASETHREE)  # Do whatever case3 needs 
                 ;;
  case4|CASEFOUR)   # Do whatever case4 needs 
                 ;;
  case5|CASEFIVE)   # Do whatever case5 needs 
                 ;;
  case6|CASESIX)    # Do whatever case6 needs 
                 ;;
  *)                # handle error
                 ;;
esac

You could also make an automatic menu with a select loop around your case statement.

Robin

1 Like

I'd present the users a menu to select from; so there's no chance for mistyping anything.

1 Like

This really worked well and the users loved the menu driven program!! Thanks for the suggestion!