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)
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)
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)
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)
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)
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)
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)
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)
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
LEARN ABOUT ULTRIX
getopt
getopt(3) Library Functions Manual getopt(3)Name
getopt - get option letter from argument vector
Syntax
#include <stdio.h>
int getopt (argc, argv, optstring)
int argc;
char **argv;
char *optstring;
extern char *optarg;
extern int optind, opterr;
Description
The subroutine returns the next option letter in argv that matches a letter in optstring. The optstring is a string of recognized option
letters; if a letter is followed by a colon, the option is expected to have an argument that may or may not be separated from it by white
space. The optarg is set to point to the start of the option argument on return from
The function places in optind the argv index of the next argument to be processed. The external variable optind is automatically initial-
ized to 1 before the first call to
When all options have been processed (that is, up to the first non-option argument), returns EOF. The special option -- may be used to
delimit the end of the options; EOF will be returned, and -- will be skipped.
Diagnostics
The function prints an error message on stderr and returns a question mark (?) when it encounters an option letter that is not included in
optstring. Setting opterr to 0 disables this error message.
Examples
The following code fragment shows how one might process the arguments for a command that can take the mutually exclusive options a and b,
and the options f and o, both of which require arguments:
#include <stdio.h>
main (argc, argv)
int argc;
char **argv;
{
int c;
extern int optind, opterr;
extern char *optarg;
.
.
.
.
while ((c = getopt (argc, argv, "abf:o:")) != EOF)
switch (c) {
case 'a':
if (bflg)
errflg++;
else
aflg++;
break;
case 'b':
if (aflg)
errflg++;
else
bproc( );
break;
case 'f':
ifile = optarg;
break;
case 'o':
ofile = optarg;
bufsiza = 512;
break;
case '?':
errflg++;
}
if (errflg) {
fprintf (stderr, "usage: . . . ");
exit (2);
}
for ( ; optind < argc; optind++) {
if (access (argv[optind], 4)) {
.
.
.
}
See Alsogetopt(1)getopt(3)