Sponsored Content
Top Forums Shell Programming and Scripting using getopt with a switch statement Post 61766 by Perderabo on Tuesday 8th of February 2005 02:28:09 PM
Old 02-08-2005
set - 'getopt frd*: $*'
is wrong. You need a double hyphen:
set -- 'getopt frd*: $*'
 

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

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

Comapilation error with Switch statement

Hello , How to resolve below compilation error.activity_type is a member of structure and the output from databse will be stored in structure.Expected output wil l be either D or N or C . sample struct format: struct a{ char acAtivity_type; } code: switch (a->activity_type)... (1 Reply)
Discussion started by: jagan_kalluri
1 Replies

5. Shell Programming and Scripting

Tcl switch statement

I am just learning Tcl and there are few things about it that is perplexing me. I have a question about the switch statement. Why are these two switch statements giving me different results? $ cat test_switch.tcl #!/usr/bin/tcl set foo "abc" switch abc a - b {puts "No. 1"} $foo {puts... (2 Replies)
Discussion started by: SFNYC
2 Replies

6. Shell Programming and Scripting

how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable

hi, how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable which needs to be connected to one console server having rj11 on its side and db 9 female on other end.i.e. on switch side,console cable has rj45 and db 9 pin female connector on other side of... (1 Reply)
Discussion started by: pankajd
1 Replies

7. Shell Programming and Scripting

Something is wrong with this switch( case statement.

I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code: while : do ... (2 Replies)
Discussion started by: snakemasterAK
2 Replies

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

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

10. Programming

Missing Logic Looping Through Switch Statement

Having trouble with the logic when looping over this switch case again: for (j = 0; data != 0; j++){ switch(data){ case 'c': output = ranit(r_brace_array); break; case 'h': output = ranit(pipe_array); break; ... (6 Replies)
Discussion started by: Azrael
6 Replies
GETOPT(3)						     Library Functions Manual							 GETOPT(3)

NAME
getopt - get option character from command line argument list SYNOPSIS
#include <stdlib.h> extern char *optarg; extern int optind; extern int optopt; extern int opterr; extern int optreset; int getopt(argc, argv, optstring) int argc; char **argv; char *optstring; DESCRIPTION
The getopt() function incrementally parses a command line argument list argv and returns the next known option character. An option char- acter is known if it has been specified in the string of accepted option characters, optstring. The option string optstring may contain the following elements: individual characters, and characters followed by a colon to indicate an option argument is to follow. For example, an option string """x"" recognizes an option ``-x'', and an option string """x:"" recognizes an option and argument ``-x argument''. It does not matter to getopt() if a following argument has leading white space. On return from getopt(), optarg points to an option argument, if it is anticipated, and the variable optind contains the index to the next argv argument for a subsequent call to getopt(). The variable optopt saves the last known option character returned by getopt(). The variable opterr and optind are both initialized to 1. The optind variable may be set to another value before a set of calls to getopt() in order to skip over more or less argv entries. In order to use getopt() to evaluate multiple sets of arguments, or to evaluate a single set of arguments multiple times, the variable optreset must be set to 1 before the second and each additional set of calls to getopt(), and the variable optind must be reinitialized. The getopt() function returns an EOF when the argument list is exhausted, or a non-recognized option is encountered. The interpretation of options in the argument list may be cancelled by the option `--' (double dash) which causes getopt() to signal the end of argument process- ing and return an EOF. When all options have been processed (i.e., up to the first non-option argument), getopt() returns EOF. DIAGNOSTICS
If the getopt() function encounters a character not found in the string optarg or detects a missing option argument it writes an error mes- sage and returns `?' to the stderr. Setting opterr to a zero will disable these error messages. If optstring has a leading `:' then a missing option argument causes a `:' to be returned in addition to suppressing any error messages. Option arguments are allowed to begin with `-'; this is reasonable but reduces the amount of error checking possible. EXTENSIONS
The optreset variable was added to make it possible to call the getopt() function multiple times. This is an extension to the IEEE Std1003.2 (``POSIX'') specification. EXAMPLE
extern char *optarg; extern int optind; int bflag, ch, fd; bflag = 0; while ((ch = getopt(argc, argv, "bf:")) != EOF) switch(ch) { case 'b': bflag = 1; break; case 'f': if ((fd = open(optarg, O_RDONLY, 0)) < 0) { (void)fprintf(stderr, "myname: %s: %s ", optarg, strerror(errno)); exit(1); } break; case '?': default: usage(); } argc -= optind; argv += optind; HISTORY
The getopt() function appeared 4.3BSD. BUGS
A single dash ``-'' may be specified as an character in optstring , however it should never have an argument associated with it. This allows getopt() to be used with programs that expect ``-'' as an option flag. This practice is wrong, and should not be used in any cur- rent development. It is provided for backward compatibility only . By default, a single dash causes getopt() to return EOF. This is, we believe, compatible with System V. It is also possible to handle digits as option letters. This allows getopt() to be used with programs that expect a number (``-3'') as an option. This practice is wrong, and should not be used in any current development. It is provided for backward compatibility only. The following code fragment works in most cases. int length; char *p; while ((c = getopt(argc, argv, "0123456789")) != EOF) switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) length = atoi(++p); else length = atoi(argv[optind] + 1); break; } } 4.3 Berkeley Distribution January 12, 1996 GETOPT(3)
All times are GMT -4. The time now is 01:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy