Verify input parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Verify input parameters
# 1  
Old 08-12-2009
Verify input parameters

I have to write a script to verify input parameters;
say esr should be YES or NO other wise the script should print an error.
This is what i tried in my script but I get the following error
[YES != YES
./test.sh[83]: [YES: not found.

esr="YES"

if [$esr != "YES" || $esr != "NO"]; then
print " Error should specify esr options YES/NO"
else
esr =$esr
fi

what am i doing wrong can anybody help me.

Thanks,
ram
# 2  
Old 08-12-2009
Basic command line argument input is $1

Code:
case $1 in
  YES )
     do something ;;
  NO )
     do something else ;;
  * )
     let the user know they messed up the input ;;
esac

For more advanced options try using the getopts function to seperate command line arguments.

Last edited by Padow; 08-12-2009 at 02:08 PM.. Reason: Changed misspelling of getopts
Padow
# 3  
Old 08-12-2009
MySQL

th problme is in:

if [$esr != "YES" || $esr != "NO"];
you need 2space in blank: 1 after [ and the second before ]

O:
if [ $esr != "YES" || $esr != "NO" ];

But you have other problem i f you want to use || the sintax correct is:

if [ $esr != "YES" ] || [ $esr != "NO" ];

other way

if [ $esr != "YES" -o $esr != "NO" ];
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to verify each line in input for specific pattern

In the bash below the out put of a process is written to input. What I am trying to do is read each line in the input and verify/check it for specific text (there are always 6 lines for each file and the specific text for each line is in the description). There will always be 6 lines in each... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. AIX

Input parameters

friends and I can validate whether to run the shell has input parameters m event date, I occasionally happen something like this does not work if $ 1 is null then echo has entered input parameters else echo "parameter ok" fi (2 Replies)
Discussion started by: tricampeon81
2 Replies

3. Shell Programming and Scripting

Verify input parameter is in the list

I need write a Korn shell which accept input parameter. But this input paramter must match one of the string in an existsing file (listkeyword). Can someone one help, how this can be done ? (3 Replies)
Discussion started by: cpchiu
3 Replies

4. Shell Programming and Scripting

How can I take input parameters after the first one?

Hi, Is there a simple way to take input of parameters after the first one? As following example, if I assign others=$2, it only takes the second one, if I assign others=$@, it will include the first one. I may try to assign others="$2 $3 $4 $5 $6 $7 $8 $9", it looks very ugly and could missing... (1 Reply)
Discussion started by: hce
1 Replies

5. Shell Programming and Scripting

Verify the input

I run the script with one parameter : myscript abc002 But I need my script to check the parameter in txt array first: txt="abc001 abc002 abc004" What's the best way to do it? I am using ksh. #! /usr/bin/ksh txt="abc001 abc002 abc004" if ; then echo " Your input is wrong,... (9 Replies)
Discussion started by: newoz
9 Replies

6. Shell Programming and Scripting

How to validate input parameters?

Hi, I wonder how I can know if the input parameters to the script are numbers or text Thanks (11 Replies)
Discussion started by: Gengis-Kahn
11 Replies

7. Shell Programming and Scripting

Problem with Input parameters

Hi, I am facing a weird problem with input parameters. Please find more details about my problem below: a) I am executing a korn shellscript with 11 input parameters from "Appworx" tool (it's a scheduling tool) and immediately displaying those 11 parameter values in unixscript and noticed... (4 Replies)
Discussion started by: npk2210
4 Replies

8. Shell Programming and Scripting

Bash Script verify user input is not empty and is equal to a value

I need to create a script that has a user enter a value. I want to verify that the value is either 1,2, or 3. If it is not then I want them to try entering it again. I am using a while loop to force them to retry. I am able to test the input against 1,2, and 3, but when I test agains an... (4 Replies)
Discussion started by: spartiati
4 Replies

9. Shell Programming and Scripting

Input parameters

I have a script which take 3 input parameters 1st - a date (i.e. current date) 2nd - type (i.e. A) 3rd - limit (i.e. 40) normally the date parameter would be current date, so I thought I could do this calculate.sh $(date +%Y-%m-%d) A 40 however, it seems like it can't be done,... (3 Replies)
Discussion started by: mpang_
3 Replies

10. Shell Programming and Scripting

Verify Parameters

I have a unix script written in the korn shell. At the top of the script I call a script that exports the values of the variables I use in my script. I know that when you execute the script using ksh -x it shows you the script running. I was wondering if there was a way you could run the script... (2 Replies)
Discussion started by: lesstjm
2 Replies
Login or Register to Ask a Question