using switch on multiple arguments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using switch on multiple arguments
# 8  
Old 04-13-2011
# 9  
Old 04-13-2011
I get "ERROR: -dsrmax not set" when using

Code:
./check-srdist.csh --dsrmax=12

Code as below

Code:
set opt_dsrmax = 0

set narg = $#argv
while ($iarg < $narg)

  MATH iarg = $iarg + 1
  set arg = $argv[$iarg]
  set opt = `echo $arg | awk 'BEGIN {FS="="} {print $1}'`
  set par = `echo $arg | awk 'BEGIN {FS="="} {print $2}'`

  switch ($opt)

  case "-d"|"--dsrmax":
    set Adsrmax = $par
    set opt_dsrmax = 1
    breaksw

  default:
    set Afullnames_list = "$Afullnames_list $arg"
    breaksw

  endsw

end   # while

if ($opt_dsrmax == 0) then
  echo "\n ERROR: -dsrmax not set\n"
  exit 1
endif

---------- Post updated at 07:47 PM ---------- Previous update was at 07:42 PM ----------

I have started coding using ksh but not bourne shell. I already got the .csh scripts and thought it would be faster to update those first so I can get some results sooner.

Quote:
Originally Posted by ctsgnb
---------- Post updated at 07:56 PM ---------- Previous update was at 07:47 PM ----------

Is it possible to do in csh?

---------- Post updated at 08:51 PM ---------- Previous update was at 07:56 PM ----------

Have tried the below and seems to work

Code:
  case "-d":
  case "--dsrmax":
    set Adsrmax = $par
    set opt_dsrmax = 1
    breaksw

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep multiple words in a file with help of fixed string switch

I have multiple strings in a file which have special character $, when i search strings by ignoring $ with \ using single quotes it returns empty results. My search strings are set char_1($lock) and set new_char_clear_3($unlock) I tried searching with but it returns empty results.However... (3 Replies)
Discussion started by: g_eashwar
3 Replies

2. Shell Programming and Scripting

Passing multiple arguments

Hi, I know with getopts you can pass arguments from the command line ./script -ab -c apple But it doesn't support 2 or more arguments for ONE option. Is there any other way to do this? Thanks (2 Replies)
Discussion started by: testa500
2 Replies

3. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. Shell Programming and Scripting

Multiple runtime arguments

I am passing 3 runtime arguments to a shell script $path crtl1 crtl2 the crtl files contains data(filename|date|count) filename.txt|02/05/2010|10 The path contains the original data file,the code should fetch (filename|date|count) from original data file and it should match... (7 Replies)
Discussion started by: Prashanth B
7 Replies

5. Shell Programming and Scripting

Multiple arguments to read

I am developing a script where 3 other scripts are included. This is a graph related script. COMPLETE IDEA: -There are 3 different graph scripts. I would like to create a master graph with all 3 in one. -User chooses the type of graph -User is asked to enter the required auguments (... (7 Replies)
Discussion started by: newkid.7955
7 Replies

6. Shell Programming and Scripting

Two arguments for optional switch

How to declare the two argument for optional switch ? I have a script that search for a string in current or old zipped log file. Im using a option something like this ${basename} Since $1 can have only one argument should be passed when user select swicth -c and -o need to... (3 Replies)
Discussion started by: baraghun
3 Replies

7. Shell Programming and Scripting

using multiple arguments in my script

hi all i am creating a script to ping hosts and then do a nslookup. So what needs to happen is that i type the script name with an argument eg: zong (script name) 172.x.x.x (IP) at the moment i have got it to take on argument, but idealy i would like it to take more than 1 argument. can you... (1 Reply)
Discussion started by: brian112
1 Replies

8. Shell Programming and Scripting

How do we pass multiple arguments into awk

How do we pass multiple arguments into awk : name=john age=12 now i have to pass both age and name into awk.. how to do it? like : awk -v var=... (4 Replies)
Discussion started by: abhinav192
4 Replies

9. Shell Programming and Scripting

Grepping multiple terms with different arguments

Grep -e 'term1' -A1 -e 'term2' -A3The above code always searches for either term and prints results + next three lines. I'm trying to print out: foo foo foo term1 bar bar bar line right after the above -- la la la la term2 so so so line right after the above and again and again I've... (7 Replies)
Discussion started by: dkozel
7 Replies

10. Shell Programming and Scripting

can't TEST multiple arguments for a file

Hi, I'm new to scripting and teaching myself how to code. Using Korn, I coded this one return "True" if a file is executable and it's not empty. However, each time I pass a file that is 777 which contains data, the script returns "false". if then echo "true" else echo... (2 Replies)
Discussion started by: cruiser
2 Replies
Login or Register to Ask a Question