Visit Our UNIX and Linux User Community


getopt in CSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getopt in CSH
# 1  
Old 07-26-2011
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!
# 2  
Old 07-26-2011
# 3  
Old 07-26-2011
hey Itkamaraj, the code you linked is in bash, i need to run it in csh.
thanks
# 4  
Old 07-26-2011
I dont know, whether u red the full page or not.

In the end of the page, you can see the below lines.

Note: In the C shell, use the following command to run the getopt command:

set argv=`getopt OptionString $*`
# 5  
Old 07-26-2011
Thanks, I regret I did miss it.
I am facing trouble in writing the <optionstring $*> part for getopt. Can you please help me out.
I will write in brief what i have understood,I need you to correct me if i am wrong anywhere.

AS is given in code
Code:
set argv = `getopt a:bc $*`

where we are trying to list flags and arguments.
hence a is a flag with arguments and b,c are just flags.

Q) What is the significance of $* after optionstring? is it just syntax? (I know what is $*=list all args)

end of getopt processing: When it has read all tokens or it has encountered a specialtoken --.
The getopt command then outputs the processed flags, a — (double hyphen), and any remaining tokens.

can you explain the bold lines above?

also, we have saved the getopt's output in a argv, so am i correct to say that argv is an array , which stores all output from a. using shift we can pop a recently used value and get ready to access next value.

---------- Post updated at 12:50 PM ---------- Previous update was at 12:15 PM ----------

Can anybody explain this getopt declaration?

Code:
set temp=(`getopt -s tcsh -o ab:c:: --long a-long,b-long:,c-long:: -- $argv:q`)

full Code Link
http://software.frodo.looijaard.name...opt-parse.tcsh

Previous Thread | Next Thread
Test Your Knowledge in Computers #252
Difficulty: Easy
Network computer devices that originate, route and terminate the data are called server-only devices.
True or False?

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

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

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

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

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

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

7. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: Guillermo Lopez
2 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

Featured Tech Videos