can getopts be used to override user input in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can getopts be used to override user input in a script
# 1  
Old 04-19-2009
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" )
hotdeploy.sh
break;;
esac
done


Now to provide these userinputs through command line args I used getopts in my script

while getopts "o:h" options; do
case $options in
o ) OPTION=$OPTARG;;
h|\?|* ) echo -e $usage
exit 1;;
esac
done


Is it possible to make my script work in two scenarios simultaneously
1. work with the user inputs given as options
2. work when user inputs are given as command line args so that it wont show the above options for user input.

Please help.
# 2  
Old 04-19-2009
How about specifying two parameters to start the script with ...

Code:
sh script -s[cenario]1
sh script -s[cenario]2

... and wrapping up the relevant code in a case-select statement:

Code:
while case $PARAM in
-s1) # 1st scenario
-s2) # 2nd scenario
esac

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. Windows & DOS: Issues & Discussions

Validation in user input in batch script

I need to insert the validation in my batch script.When user enter the value it should be numeric+minimum length should be 2 for e.g. 02,03 if he puts 1a,1A,2a3 t hen should print the message that it is wrong and print te message enter valid value. Echo RC is in format of 02 set /p... (2 Replies)
Discussion started by: anuragpgtgerman
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. Shell Programming and Scripting

getopts :- expecting required input format

The requirement is, i'm using getopts for calling two different function depending upon the input the user gives. Two functions are 1. help 2. processing function these two functions are written inside the script and if the user gives only the below format the processing function should be... (2 Replies)
Discussion started by: Amutha
2 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

Script that accepts user input - Suggestions

Hi, I have a series of BASH shell scripts that process data. All of the scripts are controlled by a "master" script, where users specify their processing parameters. The sub-scripts, and the order they are called, depend on the values of these user-specified processing parameters. This method... (1 Reply)
Discussion started by: msb65
1 Replies

9. Shell Programming and Scripting

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... (8 Replies)
Discussion started by: yoursdavinder
8 Replies

10. Shell Programming and Scripting

exit script if user input not four characters

#!/usr/bin/bash ###script to input four characters. wxyz echo "input first string" read instring1 echo "input second string" read instring2 ## echo "first string is:" $instring1 echo "second string is:" $instring2 ##IF instring1 or instring2 are NOT 4 characters (xxxx) , exit 1. ##how?? ... (2 Replies)
Discussion started by: ajp7701
2 Replies
Login or Register to Ask a Question