Verify the input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Verify the input
# 1  
Old 11-17-2010
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.

Code:
#! /usr/bin/ksh

txt="abc001 abc002 abc004"
if [ $1 not in txt ]; then
    echo " Your input is wrong, please run the script by $0 ( $txt ) "
    exit
fi

# 2  
Old 11-17-2010
If you have ksh93 this will work:

Code:
txt="abc001|abc002|abc004"
case "$1" in
    $txt) ;;
    *) echo "Your input is wrong, please run the script by $0 [$txt]"
    exit ;;
esac

If not, you will need to eval the whole case statement - watch imbedded quotes
Code:
txt="abc001|abc002|abc004"
eval "case \"$1\" in
    $txt) ;;
    *) echo \"Your input is wrong, please run the script by $0 [$txt]\"
    exit ;;
esac "


Last edited by Chubler_XL; 11-17-2010 at 11:43 PM..
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 11-18-2010
The second one works in my env.

But my env has been set by txt="abc001 abc002 abc004" (split by space, not |)

Can you update from this?
# 4  
Old 11-18-2010
Just setup another var with pipes (txt2 in this case):

Code:
txt="abc001 abc002 abc004"
txt2=`echo $txt | sed 's/ /|/g'`
eval "case \"$1\" in
    $txt2) ;;
    *) echo \"Your input is wrong, please run the script by $0 [$txt2]\"
    exit ;;
esac "

# 5  
Old 11-18-2010
The same, without echo and sed
Code:
txt="abc001 abc002 abc004"
case $1 in
    ${txt// /|}) ;;
    *) echo "Your input is wrong, please run the script by $0 [$txt]"
    exit ;;
esac

# 6  
Old 11-18-2010
@frans: that will not work in ksh88. It isn't clear what version the OP has..
# 7  
Old 11-18-2010
Quote:
Originally Posted by Scrutinizer
@frans: that will not work in ksh88. It isn't clear what version the OP has..
I try to check the ksh version, but I don't know.

Code:
$ ksh --help
$ exit


$ ksh -VER
-VER: bad option(s)

$ ksh -v
$

My system is solaris 10. Can you tell me how to check the ksh version?
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. Red Hat

Verify multipathing

I have a couple of questions regarding multipath. If I do vgdisplay vg01, I see it is using 1 PV: /dev/dm-13 If I type multipath -ll I see dm-9, dm-10, dm-11, dm-12, but do not see dm-13. Is my vg01 multipathed? How can I actually know for sure? Secondly, let's say this time vg01 says... (1 Reply)
Discussion started by: keelba
1 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

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Hardware

Verify patching

I patched a linux kernel 2.6.28 with lttng patch. Now I have two folder of linux patched and unpatched. How can I verify whether the linux is patched or unptahced(original version)? (0 Replies)
Discussion started by: rupeshkp728
0 Replies

6. AIX

verify command

Guy's I have script doing many steps as the below ... ############# ## step1# mount all Files system mount all ## step2# Start the application /app/appsh ############# but some time mount points will not be mounted completely so that will give an error if the next step started... (1 Reply)
Discussion started by: Mr.AIX
1 Replies

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

8. Shell Programming and Scripting

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 : esr="YES" if ; then print " Error should specify esr options YES/NO" else esr =$esr fi ... (2 Replies)
Discussion started by: ramky79
2 Replies

9. Shell Programming and Scripting

verify arguments

thanks for your help, im gonna skip this one and try a different question. thanks for your help though. (2 Replies)
Discussion started by: bebop1111116
2 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