Read with two values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read with two values
# 1  
Old 09-11-2014
Read with two values

I have a script like this:

Code:
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

Code:
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:.

Code:
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?
# 2  
Old 09-11-2014
Have you considered a case statement in your script? - not to be confused with them entering the word case6 or CASESIX

Something like:-
Code:
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
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 09-11-2014
I'd present the users a menu to select from; so there's no chance for mistyping anything.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 09-18-2014
Thanks!

This really worked well and the users loved the menu driven program!! Thanks for the suggestion!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

2. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

3. Shell Programming and Scripting

While loop to read values

Hi Everyone, I am currently tasked with some reporting on various Unix based OSes. I have a script deployed that runs and grabs the information I am looking for, and has a bit of logic to output the desired result into a text file. Example of my text file: multiUsers=yes... (1 Reply)
Discussion started by: Zaphod_B
1 Replies

4. Shell Programming and Scripting

Read values from file.

I have a config file of this format: Company= Alpha Tech From Email = AlphaTech@Alphatech.com Pass = Passowrd To Email = abc@hotmail.com Smtp=smtp.live.com:587 I want to read these values from this file and use in a command to send email. I am trying grep but it gives full line. I just... (8 Replies)
Discussion started by: kashif.live
8 Replies

5. Shell Programming and Scripting

To read the values and to use in the where condition

Hi, I have the below values in a text file. 'xx.16397950', 'xx.16397957', 'xx.16397976', 'xx.16473259', I need to use in the where clause of the sql query in my unix shell script. How to read one by one value. It should be like this: select * from <<table name>> where xx in (... (10 Replies)
Discussion started by: venkatesht
10 Replies

6. Shell Programming and Scripting

Read variables and their values from file

Hi, I want to read the variables and the values from the txt file and compare these values with the ones computed by script. for ex: say var.txt contains the variable names and their values: one 1 two 2 three 3 The value of variables "one" "two" and "three" will be computed in the script... (3 Replies)
Discussion started by: bhushana
3 Replies

7. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

8. Shell Programming and Scripting

Not able to read unique values in array

Hi Friends, I am having some trouble reading into an array. Basically, I am trying to grep for a pattern and extract it's value and store the same into an array. For eg., if my input is: <L:RECORD>name=faisel farooq,age=21, company=TCS,project=BT</L:RECORD> <L:RECORD>name=abc... (1 Reply)
Discussion started by: faiz1985
1 Replies

9. Shell Programming and Scripting

read column values one after another

hi, Can some one help me how to retrieve column values row by row My requirement is like below : I have a text file having comma seperated values of these records . OName OType SrcDB Sschema targetdb TSchema Load Dataype processY/N aa Table a e i m Y db2 y aa index b c d e N sql N ... (4 Replies)
Discussion started by: sailaja_80
4 Replies

10. Shell Programming and Scripting

Read values from a file

Hi , I have a file with the following content I need the read the year and reporting from this file and store them in variables. I understand that we can read the file delimited by'=' but not sure how to extract the values correctly. Thanks in advance Regards (3 Replies)
Discussion started by: w020637
3 Replies
Login or Register to Ask a Question