getopt/getopts and csh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers getopt/getopts and csh
# 1  
Old 04-25-2008
getopt/getopts and csh

Is there a way to get getopt/getopts to work in csh?
I know... csh is not a good shell. Nobody should be using it but I have to deal with old scripts already coded using this shell and therefore I have to do some maintenance to them...

Any ideas about how to get it to work? I did recode some sh scripts using getopts and didn't work for me :-(
# 2  
Old 04-25-2008
maybe you should say WHAT doesn't work or post the code that doesn't work....
# 3  
Old 04-25-2008
Quote:
Originally Posted by DukeNuke2
maybe you should say WHAT doesn't work or post the code that doesn't work....
Well... It's not that simple to explain what's wrong but at least I can't get the outcome I'd expect with a very simple example. Here's the sample code that worked for me in sh shell:

Code:
#!/bin/sh

while getopts a:b:cde opt
do
        case "$opt" in
                a) echo "hello $OPTARG";;
                b) echo "hello $OPTARG";;
                c) echo "c flag";;
                d) echo "d flag";;
                e) echo "e flag";;
                \?) echo "Usage: $0 -c -d -e -a a -b b";;
        esac
done

And here's the same sample code translated to csh that didn't work:

Code:
#
!/bin/csh

while (`getopts a:b:cde opt`)
switch ($opt)
        case -a:
                echo "hello $OPTARG"
                breaksw
        case -b: 
                echo "hello $OPTARG"
                breaksw
        case -c: 
                echo "c flag"
                breaksw
        case -d 
                echo "d flag"
                breaksw
        case -e: 
                echo "e flag"
                breaksw
        default:
                echo "Usage: $0 -c -d -e -a a -b b"
                breaksw
endsw
end

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getopt Help

Hi All, An old work friend wrote a script which I've been trying to understand how a section of it currently works and work out how i can add some command line switches which i can use later in the script to append the output depending on the command line arguements. Currently it works by... (1 Reply)
Discussion started by: mutley2202
1 Replies

2. Shell Programming and Scripting

getopt in CSH

I am struggling to understand how getopt can be used in a csh script. can anybody post a csh script using getopt. Please! (4 Replies)
Discussion started by: animesharma
4 Replies

3. Shell Programming and Scripting

Help with Getopt::Std

I am working on a script that lists files in a directory with a few file attributes depending on what option the user specifies at the command prompt. The script uses Getopt::Std and takes two switches. The first switch allows the user to specify a directory, the second switch gives a long... (3 Replies)
Discussion started by: Breakology
3 Replies

4. Shell Programming and Scripting

Help with getopt

Hi, I want to use the getopt function to parse some arguments for a script. while getopts "i:f:r:" OPTION do case $OPTION in i) iter=$OPTARG;; f) frame=$OPTARG;; r) roi=$OPTARG;; ?) echo Usage: ...... exit 2;; esac done However, I... (5 Replies)
Discussion started by: giorgos193
5 Replies

5. Shell Programming and Scripting

getopt help

:) Can anybody help me about how to use getopt in shell scripting. (3 Replies)
Discussion started by: darshakraut
3 Replies

6. Shell Programming and Scripting

getopt help

I m trying to use getopt This is my script, but it doesn't take argument in variable, Please help. set - - `getopt mscl: $*` if then echo "Exiting...." exit 2 fi for i in $* do case $i in -m) MAIL="$i"; shift;; -s) SCRIPT=$OPTARG; shift;; -c) COB=$OPTARG; shift;;... (2 Replies)
Discussion started by: darshakraut
2 Replies

7. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

8. Shell Programming and Scripting

getopt

#!/bin/sh set -- `getopt "abco:" "$@"` a= b= c= o= while : do case "$1" in -a) a=1;; -b) b=1;; -c) c=1;; -o) shift; o="$1";; --) break;; esac shift done shift # get rid of -- # rest of script... # e.g. ls -l $@ (6 Replies)
Discussion started by: Hitori
6 Replies

9. Shell Programming and Scripting

getopt help

scriptname i have made a script to perform so tasks and i managed to complete the tasks for all the options the problem i am facing is that i can run the scripts individually but i would like to make it such that it can accept multiple options and give me the appropriate output e.g.... (1 Reply)
Discussion started by: problems
1 Replies

10. Programming

question about getopt()

I'm using getopt() to get command line options.One the optons accepts and argument.The argument is and offset.I was wondering how can I scecify that it's argument is of the type off_t.I've something like this "offset=(off_t)optarg" and it don't work. (1 Reply)
Discussion started by: angelfly
1 Replies
Login or Register to Ask a Question