Sponsored Content
Top Forums Shell Programming and Scripting Adding another option to getopt Post 302821043 by Alabama on Friday 14th of June 2013 01:44:15 AM
Old 06-14-2013
Thank you, just did, but still getting "invalid option --D".
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding an Option

I have a file that takes 2 or 3 arguments... ie: $argv(2), $argv(3) If I had to add another argument, I would be ok, but nooo.. that would be too easy for the new programmer. Before you go there - This is not a school problem, it's a real world problem.. If I wanted to add an option, for... (1 Reply)
Discussion started by: Brusimm
1 Replies

2. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 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. Programming

probs adding linker option in g++

Hi all Im trying to compile a C++ program, however Im having issues trying to link a particular library to the compiling and linking statement. Here is what Im doing g++ mips4 -std=c++98 -g disk_reporter.cpp -o disk_reporter If I do this alone, the linker complains that library... (2 Replies)
Discussion started by: JamesGoh
2 Replies

6. Shell Programming and Scripting

--alternative option in getopt

Hi, i need to use --alternative option of getopt for ex . getopt -o a:c: --alternative pw: -- "$@" if i use like this, i am not getting any output.Please help me how to correct this.i need to have a combination of long and short options.But long options have to begin with - and not... (0 Replies)
Discussion started by: padmisri
0 Replies

7. UNIX for Dummies Questions & Answers

Using Getopt Option

Hi I need to use getopt option and I have no idea what it is or how to use it. I need to use it on this awk script: awk -F, -v cellid="$1" -v paramval="$2" -v oldfile="$3" -v newfile="$4" '$2==cellid{$3=newvalue}1' OFS="," $3 > $4 I tried reading up on it but I just confuse... (2 Replies)
Discussion started by: ladyAnne
2 Replies

8. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

9. Shell Programming and Scripting

getopt invalid option selection

What is the significance of the *) and ?) in the below code. while getopts a:b:c:he opt do case $opt in a) _name="$OPTARG";; b) _project="$OPTARG";; c) line="$OPTARG";; e) _cmd="XX";; h) Projects=1;; *) echo "$OPTARG is an invalid option"; my_exit 1;; ?)... (3 Replies)
Discussion started by: posix
3 Replies

10. Shell Programming and Scripting

[Solved] adding email option to KSH

Hi, I wanted to add a email option to this script. and was wondering if anyone could help me out. #!/bin/ksh echo "Finding hdisk" <DIR>/find-disk i=1 b=0 p=0 while ... (2 Replies)
Discussion started by: vpundit
2 Replies
GETOPT(3)						   BSD Library Functions Manual 						 GETOPT(3)

NAME
getopt -- get option character from command line argument list LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> extern char *optarg; extern int optind; extern int optopt; extern int opterr; extern int optreset; int getopt(int argc, char * const argv[], const char *optstring); DESCRIPTION
The getopt() function incrementally parses a command line argument list argv and returns the next known option character. An option charac- ter 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 variables 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 -1 when the argument list is exhausted. 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 processing and return -1. When all options have been pro- cessed (i.e., up to the first non-option argument), getopt() returns -1. RETURN VALUES
The getopt() function returns the next known option character in optstring. If getopt() encounters a character not found in optstring or if it detects a missing option argument, it returns '?' (question mark). If optstring has a leading ':' then a missing option argument causes ':' to be returned instead of '?'. In either case, the variable optopt is set to the character that caused the error. The getopt() function returns -1 when the argument list is exhausted. EXAMPLES
#include <unistd.h> int bflag, ch, fd; bflag = 0; while ((ch = getopt(argc, argv, "bf:")) != -1) { 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; DIAGNOSTICS
If the getopt() function encounters a character not found in the string optstring or detects a missing option argument it writes an error message to the stderr and returns '?'. 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. SEE ALSO
getopt(1), getopt_long(3), getsubopt(3) STANDARDS
The optreset variable was added to make it possible to call the getopt() function multiple times. This is an extension to the IEEE Std 1003.2 (``POSIX.2'') specification. HISTORY
The getopt() function appeared in 4.3BSD. BUGS
The getopt() function was once specified to return EOF instead of -1. This was changed by IEEE Std 1003.2-1992 (``POSIX.2'') to decouple getopt() from <stdio.h>. A single dash ``-'' may be specified as a 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 current devel- opment. It is provided for backward compatibility only. Care should be taken not to use '-' as the first character in optstring to avoid a semantic conflict with GNU getopt(), which assigns different meaning to an optstring that begins with a '-'. By default, a single dash causes getopt() to return -1. 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 ch; long length; char *p, *ep; while ((ch = getopt(argc, argv, "0123456789")) != -1) switch (ch) { 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 = ch - '0'; ep = ""; } else if (argv[optind] && argv[optind][1] == ch) { length = strtol((p = argv[optind] + 1), &ep, 10); optind++; optreset = 1; } else usage(); if (*ep != '') errx(EX_USAGE, "illegal number -- %s", p); break; } BSD
April 27, 1995 BSD
All times are GMT -4. The time now is 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy