User input for execution of script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User input for execution of script
# 1  
Old 01-29-2009
User input for execution of script

Hi,

I need to get the user input and execute a particular script based on the input provided.

For E.g. When I execute the script say Test.sh it should prompt "For which country I need to execute the script? (US/India)"

Based on the input as US or India from the user the execution of the steps in the script need to be done.

I have put some sample code can anyone please help me correct it and get the execution done successfully? How can I accept the user input ??

Code:

$ECHO $n "Enter the Country for which you want the installation to be executed? (US/India). $C"
if [ "${COUNTRY_SPEC}" = "US" -o "${COUNTRY_SPEC}" = "us"]
then
COUNTRY=US
else
COUNTRY=India
fi
echo -e "The installation is for $COUNTRY"
# 2  
Old 01-29-2009
To accept user input use the read command immediately after your echo.

echo "Enter the Country for which you want the installation to be executed? (US/India). \c"
read COUNTRY_SPEC

if [ "${COUNTRY_SPEC}" = "US" -o "${COUNTRY_SPEC}" = "us" ]
then
COUNTRY=US
else
COUNTRY=India
fi

echo -e "The installation is for $COUNTRY"

Last edited by ronnie_uk; 01-30-2009 at 05:34 AM..
# 3  
Old 01-29-2009
might be clearer and more efficient to use a case sequence instead of a for loop.

that way, you could have the third entry for "*" to prompt for the correct country.

case $COUNTRY_SPEC in
US) .....;;
India) ....;;
*) echo "please enter correct country";;
esac
# 4  
Old 01-30-2009
I have written the following code and the result as follows. Can you help? Thanks.

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

Result:
: No such file or directorye Country for which you want the installation to be executed? (US/India)
US
': not a valid identifier`
: command not found
./Test.sh: line 24: syntax error: unexpected end of file
# 5  
Old 01-30-2009
Whats the value of your $ECHO variable? Could you run your script with set -x and post the output?
And please, do not doublepost
# 6  
Old 01-30-2009
Not sure why you are trying to use $ECHO variable to echo a message to the screen. If you are only trying to prompt the user to enter a value then use this:

echo "Enter the Country for which you want the installation to be executed? (US/India) "
read COUNTRY_SPEC
# 7  
Old 01-30-2009
when im just trying to echo as mentioned by you:
echo "Enter the Country for which you want the installation to be executed? (US/India) "
read COUNTRY_SPEC

I am getting:
line 1: ECHO: command not found
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Me. The script should not exit until the user gives an input.

Hi everyone, I'm new here and just a beginner in linux scripting. Just want to ask for help on this one. I am trying to create a script that will accept user input (year-month and user/s). I wanted to have the script to continue running, until the user inputs a DATE and name/s of user/s. ... (2 Replies)
Discussion started by: Helskadi
2 Replies

2. Shell Programming and Scripting

Execution problem with shell script for modifying a user

#/bin/sh echo "enter the user name" read $username echo "Enter new home directory" read $newhd usermod -d $newhd $username ;; error while executing : enter the user name Rev Enter new home directory: /home/58745 usermod: option requires an argument -- 'd' Try `usermod --help' or... (2 Replies)
Discussion started by: Revanth547
2 Replies

3. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

4. Programming

Perl script remote execution as another user

Hi gurus, I have a requirement where I need to remotely run a perl script as another user. Running the script locally as the required user is fine, however I need to su with the script due to filesystem permission issues. I do not want to update permissions on the remote server due to security... (5 Replies)
Discussion started by: melias
5 Replies

5. Shell Programming and Scripting

How to take input from user or awk script?

Hi Jim, I have following script,i which i need to take dynamic value . script, nawk -v v1=grep"INT_EUR" $propertifilename | cut -d"=" -F2` -F'~' '{if (NF-1 !=v1) {print "Error in " $0 " at line number "NR" tilde count " N-1}}' $filename In the above script i want to use INT_EUR as a variable... (2 Replies)
Discussion started by: Ganesh Khandare
2 Replies

6. Shell Programming and Scripting

User Input Shell Script

Hello I am trying to create a user input shell scipt. The objective is user should enter the circuit number and the input is saved in a log file. If the user does not enter anything then the question should prompt it until the circuit no. is entered. Can any one please correct the code below.... (3 Replies)
Discussion started by: sureshcisco
3 Replies

7. Shell Programming and Scripting

Expect script without user seeing output or input

I want a shell script to call an expect script but I want the expect script to run in the background so the user is not bothered with what is going on. Is there any way to do this? ---------- Post updated at 08:23 PM ---------- Previous update was at 07:39 PM ---------- got it it was ... (1 Reply)
Discussion started by: los21282
1 Replies

8. Shell Programming and Scripting

Give input to a perl script while execution

Hi, I have a perl script which prints me the epoch value of a specific date and time given.Now I want to proceed to a next step ie i want to give the input at the time of execution. I have to initialise the date and time values in the script before executing it.But now i want to give the date... (3 Replies)
Discussion started by: jyothi_wipro
3 Replies

9. Shell Programming and Scripting

geting user input from php and using perl for execution

I am using festival speech synthesis system and I would like to allow user input in a browser. This will be taken by a php page which is then supposed to pass the input text to a perl script. The perl script should pass this text to the festival engine by executing a unix command. this in turn... (2 Replies)
Discussion started by: wairimus
2 Replies

10. Shell Programming and Scripting

can getopts be used to override user input in a script

I have a script which takes user input as options provided PS3="Select option to do deploy : " select OPTION in "eardeploy" "hotdeploy" do case $OPTION in "eardeploy" ) eardeploy.sh break;; "hotdeploy" ) ... (1 Reply)
Discussion started by: codeman007
1 Replies
Login or Register to Ask a Question