Storing Command Line Values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Storing Command Line Values
# 1  
Old 01-30-2009
Storing Command Line Values

Hi,
I am trying to read the value passed by the user and store it in a variable so that later I can read it from the variable. But I am getting errors. Can you please help? Thanks.

Code:
$ECHO "Enter the Country for which you want the installation to be executed? (US/India):"
read COUNTRY
if [ "$COUNTRY" = "us" -o "$COUNTRY" = "US" ]
then
$COUNTRY="US"
else
$COUNTRY="India"
fi
$echo "The installation is for: $COUNTRY"

Execution Result:
./Country_Test.sh: line 4: Enter the Country for which you want the installation to be executed?: command not found
us
./Country_Test.sh: line 8: us=US: command not found
./Country_Test.sh: line 13: The installation is for: us: command not found
# 2  
Old 01-30-2009
Code:
echo "Enter the Country for which you want the installation to be executed? (US/India):"
read COUNTRY
if [ "$COUNTRY" = "us" -o "$COUNTRY" = "US" ]
then
    COUNTRY="US"
else
    COUNTRY="India"
fi
echo "The installation is for: $COUNTRY"

# 3  
Old 01-30-2009
$ECHO makes no sense. The command is echo.

To be independent from the case of the characters that have been input, you can use this:

Code:
cat mach.ksh:


echo "Enter the Country for which you want the installation to be executed? (US/India):"

read COUNTRY

COUNTRY=`echo ${COUNTRY} | tr -s '[A-Z]' '[a-z]'`

case ${COUNTRY} in
        us)     COUNTRY="US";;
        india)  COUNTRY="India";;
esac

echo Country: ${COUNTRY}

Example:
Code:
./mach.ksh
Enter the Country for which you want the installation to be executed? (US/India):
uS
Country: US

./mach.ksh
Enter the Country for which you want the installation to be executed? (US/India):
iNdIA
Country: India


Last edited by zaxxon; 01-30-2009 at 07:39 AM.. Reason: Corrected formatting
# 4  
Old 01-30-2009
No duplicate or cross-posting, please read the rules.

Double post of:

https://www.unix.com/shell-programmin...#post302281977

Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

storing multiple values in a array variable

Am using a find command in my script .The output may be one or more. I need to store those values in a array and need to access those. Am unable to find the solution . Any help on this will be helpful. if < code> else a=<find command output which gives the file name either 1 or more> if 1... (1 Reply)
Discussion started by: rogerben
1 Replies

2. UNIX for Dummies Questions & Answers

Storing values in shell variable

Hi, I am writing a shell script where, x=y y=z When I want to print z, I can do $y How do I use only "x" without any direct reference to "y" to print z? Thanks, -G (3 Replies)
Discussion started by: gaurab
3 Replies

3. Shell Programming and Scripting

Storing values in arrays

I have the following csh script which lets the use pass the following as an argument -legend=tag1/tag2/tag3/tag4/tag5/tag6/tag7 We pass a number of tags separated by '/'. I want to save the legend tags in an array and have done as below. How can I improve on this as things are getting quite... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Shell Programming and Scripting

Storing values in arrays using csh

I am reading a number of files but then I want to put the ranges xmin xmax ymin ymax as arrays for each file. Any idea how I can do this??? set j = 1 echo "Welcome $i times" while ( $j <= $i ) echo "$j" set fname = $fin-bst-misf.xy echo " "$fname ... (0 Replies)
Discussion started by: kristinu
0 Replies

5. Shell Programming and Scripting

storing values in arrays using shell

Friends, I have to execute a command and store its contents into an array using shell. this is what i have tried #!/bin/bash disk_names = ($(`iostat -xtc | egrep -v "device|nfs" | awk '{print $1}'| tr '\n' ' ' `)) But its throwing an error message as ./test-script ./test-script:... (6 Replies)
Discussion started by: achak01
6 Replies

6. Shell Programming and Scripting

fetching values using awk and storing into array

hi all I am using awk utility to parse the file and fetching two different vaues from two different record of a record set. I am able to see the result, now i want to store the result and perform some check of each values form database to mark valid and invalid. could you please help me... (3 Replies)
Discussion started by: singhald
3 Replies

7. Shell Programming and Scripting

storing values in a list or array

i have a file called file.txt having the following entries. 2321 2311 2313 4213 i wnat to store these values in a list and i want to iterate the list using loop and store it in another list (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

8. UNIX for Dummies Questions & Answers

Storing Multiple Values in a Variable

Hi, My code is as below: integer i=7 while ((i <= 5 )); do # test_out is a variable which contains data separated by "^". a= `echo $test_out | cut -d"^" -f$i` echo "$a" (( i = i + 1)); done From the above code, i kept $i after f so that i can capture all the data which is... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

9. Programming

Need help in storing command line argument argv[2] to a variable of int type

The following program takes two command line arguments. I want the second argument (fileCount) to be stored/printed as a int value. I tried my best to typecast the char to int (check the printf statement at last) but is not working...the output is some junk value. This program is in its... (3 Replies)
Discussion started by: frozensmilz
3 Replies

10. Shell Programming and Scripting

Storing values in variable

Hi All, Here is the description of the problem. I am scripting for database access using k-shell on solaris box dbaccess <databasename> - << EOF 2>/dev/null | awk 'BEGIN {FS=" "}\ {printf "%s", $1}' | grep -v "^$" | \ read cnt1 OUTPUT TO PIPE cat WITHOUT HEADINGS select count(*) from... (1 Reply)
Discussion started by: matrixmadhan
1 Replies
Login or Register to Ask a Question