Sponsored Content
Full Discussion: question about getopt()
Top Forums Programming question about getopt() Post 28230 by hell666 on Monday 16th of September 2002 02:04:36 AM
Old 09-16-2002
'optarg' is of type 'string' (char *). If 'off_t' is of type int, use atoi() to convert optarg to type off_t.
 

10 More Discussions You Might Find Interesting

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

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

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

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

use of getopt command

Hi All, Could anyone tell me how to use getopt command.....? Thanks, Pintu (2 Replies)
Discussion started by: pintupatro
2 Replies

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

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

8. Shell Programming and Scripting

Perl Getopt::Long question - stopping multiple args

Hi there, I have an example basic script (below) and ive been trying to figure out how to stop multiple arguments to my options occuring. for example using the example script below I can issue two arguments for, say the --surname option and it will not barf at me (although thats what i want it to... (11 Replies)
Discussion started by: rethink
11 Replies

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

10. 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
GETOPT(1)						    BSD General Commands Manual 						 GETOPT(1)

NAME
getopt -- parse command options SYNOPSIS
args=`getopt optstring $*` ; errcode=$?; set -- $args DESCRIPTION
The getopt utility is used to break up options in command lines for easy parsing by shell procedures, and to check for legal options. Optstring is a string of recognized option letters (see getopt(3)); if a letter is followed by a colon, the option is expected to have an argument which may or may not be separated from it by white space. The special option '--' is used to delimit the end of the options. The getopt utility will place '--' in the arguments at the end of the options, or recognize it if used explicitly. The shell arguments ($1 $2 ...) are reset so that each option is preceded by a '-' and in its own shell argument; each option argument is also in its own shell argu- ment. EXIT STATUS
The getopt utility prints an error message on the standard error output and exits with status > 0 when it encounters an option letter not included in optstring. EXAMPLES
The following code fragment shows how one might process the arguments for a command that can take the options -a and -b, and the option -o, which requires an argument. args=`getopt abo: $*` # you should not use `getopt abo: "$@"` since that would parse # the arguments differently from what the set command below does. if [ $? -ne 0 ]; then echo 'Usage: ...' exit 2 fi set -- $args # You cannot use the set command with a backquoted getopt directly, # since the exit code from getopt would be shadowed by those of set, # which is zero by definition. while true; do case "$1" in -a|-b) echo "flag $1 set"; sflags="${1#-}$sflags" shift ;; -o) echo "oarg is '$2'"; oarg="$2" shift; shift ;; --) shift; break ;; esac done echo "single-char flags: '$sflags'" echo "oarg is '$oarg'" This code will accept any of the following as equivalent: cmd -aoarg file file cmd -a -o arg file file cmd -oarg -a file file cmd -a -oarg -- file file SEE ALSO
getopts(1), sh(1), getopt(3) HISTORY
Written by Henry Spencer, working from a Bell Labs manual page. Behavior believed identical to the Bell version. Example changed in FreeBSD version 3.2 and 4.0. BUGS
Whatever getopt(3) has. Arguments containing white space or embedded shell metacharacters generally will not survive intact; this looks easy to fix but is not. Peo- ple trying to fix getopt or the example in this manpage should check the history of this file in FreeBSD. The error message for an invalid option is identified as coming from getopt rather than from the shell procedure containing the invocation of getopt; this again is hard to fix. The precise best way to use the set command to set the arguments without disrupting the value(s) of shell options varies from one shell ver- sion to another. Each shellscript has to carry complex code to parse arguments halfway correctly (like the example presented here). A better getopt-like tool would move much of the complexity into the tool and keep the client shell scripts simpler. BSD
January 26, 2011 BSD
All times are GMT -4. The time now is 01:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy