Pass values to case statement in a function korn shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass values to case statement in a function korn shell
# 1  
Old 03-11-2013
Pass values to case statement in a function korn shell

I'm in the process of writng a function that consists of a case statement is there a way of calling the function and passing a value to it?

ie

function1 () {
case
opt1 do .....
opt2 do.....
esac
}

function opt1

I'm aware the syntax is not correct, but you get the general idea.
# 2  
Old 03-11-2013
Code:
function function1() {
case $1 in
        1) do something ;;
        2) do other something ;;
        [3-9]) do some other something ;;
esac
}

call it with function1 $opt1
This User Gave Thanks to verdepollo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting with case statement

Foe example we have three environments int,qa and prod.Each environment has some number of servers. int=Server1,Server2,Server3 qa=Server4,Server5,Server6 prod=Server7,Server8,Server9 echo "Enter the Environment i.e int,qa,prod" read env case $env in int) ## Need command where all the... (9 Replies)
Discussion started by: nareshreddy443
9 Replies

2. Shell Programming and Scripting

Using shell to generate case statement

Hi Gurus, I have a very weird requirement and have no clue to resolve the issue. please help me get out this difficulty below two tables, table1 contains the column name. D means this column used for the rule. for example: rule 0 is all columns have value, rule1 is col3 and col7 have no value.... (2 Replies)
Discussion started by: Torhong
2 Replies

3. Shell Programming and Scripting

Korn shell script - SQL statement challenges

Hi scripting experts. I have some coding challenges that I'm hoping you can help me out. I have one file#1 that contains the following sql statement that spans over multiple lines: sql Select /*+ use_has(a,b) */ * from customer a, customer_address b where a.id = b.id... (1 Reply)
Discussion started by: pchang
1 Replies

4. Programming

pass value from Oracle sql to Korn shell

Hi All , I am trying to pass a value from sqlplus to korn shell . There is a table tab1 in Oracle that has a column userdate. I need to pass the userdate to the korn shell . This is what I am doing . VALUE=`sqlplus -silent username/password << END set pagesize 0 feedback off verify off... (14 Replies)
Discussion started by: megha2525
14 Replies

5. Shell Programming and Scripting

Running a function from a case statement

Hi, I have the below script that should take the command line option and run the desired script on another server. Only it doesn't seem to run the function, infact it just returns back to the command line. case $1 in 1) msgbacklog() ;; 2) jobstatus() ;; ... (10 Replies)
Discussion started by: chris01010
10 Replies

6. Shell Programming and Scripting

Shell case statement

echo -e "Select: \c" read IN pattern="1-20" case $IN in ) echo "Selected: $IN" ;; *) echo "Invalid selection: $IN" ;; esac # sh test Select: 10 Invalid selection: 10 # sh test Select: 2 (6 Replies)
Discussion started by: Ikon
6 Replies

7. Shell Programming and Scripting

Using Subroutine / Function in case statement

I have issue running functions under case statement #!/bin/bash single() { Commands } multiple() { Commands } until ; do echo -e " \t \t M A I N - M E N U Perforce delete script \n" (1 Reply)
Discussion started by: sriram003
1 Replies

8. Shell Programming and Scripting

shell script case statement

In a case statement like below : case $rental in "car") echo "For $rental Rs.20 per k/m";; "van") echo "For $rental Rs.10 per k/m";; "jeep") echo "For $rental Rs.5 per k/m";; "bicycle") echo "For $rental 20 paisa per k/m";; *) echo "Sorry, I can not gat a $rental for you";;... (4 Replies)
Discussion started by: sriram003
4 Replies

9. UNIX for Dummies Questions & Answers

if test case in korn shell

hi, I am new to this forum and this is my first post. I am not too familiar with scripting so I will be spending a lot of time here. I am trying to understand a ksh script. NSCA=/bin/send_nsca if ] What does the -e check for? (3 Replies)
Discussion started by: fluke_perf
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell to bash - statement not working

Everything else seems to be working, but this isn't. Is it the "cat..." that is wrong of the condition? Thanks. cat tc_result.txt | while read LINE do if then let "files_run += 1"; echo "inside the if loop" # save current filetype case $LINE... (5 Replies)
Discussion started by: brdholman
5 Replies
Login or Register to Ask a Question