07-31-2016
If you are trying to have 4 scenarios, why does you script run the usage macro in three of the 4 scenarios (only moving on to the final two echo commands in your script if both options are present on the command line?
Please describe what you want your script to do in these 4 scenarios. Without knowing what these 4 scenarios are, I don't see how we can guess at how to correct your script.
And, what is the format of the -i and -e option-arguments. From your code I assume that the strings include: or exclude:, respectively, must occur somewhere in the option-arguments (not necessarily at the start of those option-arguments), but why these strings are needed (rather than assumed from the option-letter) is not clear, what else is expected in those option-arguments is not clear, and whether or not some default value should be used for these option-arguments if the options are not specified on the command line is not clear.
Please also show us an actual synopsis for your utility showing the utility name, the options, and operands that are expected in the various valid manners in which your utility can be invoked. (For example, the string -query appears at the end of your usage statement. Is that an indication that there are 4 more options (-q, -u, -r, and -y as well as a -e without an option-argument), or is it another mandatory string that is supposed to appear as the final operand to your utility?
You seem to have several operands that are required to be constant pathnames. Why does a user have to type in a constant pathname when your script could supply it automatically without the user having to type it in every time your script is invoked?
This User Gave Thanks to Don Cragun For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need to parse parameters but the arguments could be NULL,example:
> cat getopts.sh
while getopts "a:b:" opt 2>/dev/null
do
case "${opt}" in
a) echo "A:${OPTARG}" ;;
b) echo "B:${OPTARG}" ;;
*) exit 1 ;;
esac
done
> getopts.sh -a TEST1 -b TEST2... (5 Replies)
Discussion started by: Klashxx
5 Replies
2. Shell Programming and Scripting
while getopts l:f:s:o:h: c
do
case $c in
l) tail -${OPTARG} /etc/passwd
exit 2;;
f) head -${OPTARG} /etc/passwd
exit 3;;
s) grep ${OPTARG} /etc/passwd | cut -d: -f7
exit 4;;
o) OARG=$OPTARG
exit 5;;
h) ... (3 Replies)
Discussion started by: nadman123
3 Replies
3. Shell Programming and Scripting
Hi, I am a new member to unix.com.
Actually I am facing a problem with getopts. In my script i have used getopts to parse the parameters. when i use the script as shown below its working fine:
find_status -p all ### where find_status is a script name.
But even if I pass more than one... (3 Replies)
Discussion started by: pvamsikr
3 Replies
4. UNIX for Advanced & Expert Users
i was going through the man page of getopts
this particular section is not clear to me can anyone please
clarify in a little detail so that i can understand the concept
MANPAGE::
Since getopts affects the current shell execution environ-
ment, it is generally provided as a... (7 Replies)
Discussion started by: mobydick
7 Replies
5. HP-UX
Is there a restriction on levels of using 'getopts' ? I have several scripts, each of which requires an option as the first parameter .
If I call one prg separately it works fine, but when one prg calls another prg and passes the option on the called prg, then the called prg
seems not to process... (3 Replies)
Discussion started by: vslewis
3 Replies
6. Shell Programming and Scripting
How do I get the getopts command to display whats written at my help option if no option is types in? For example,
myscript.sh -h
will bring up my help option, however, I also want
myscript.sh
to do the same!
#!/bin/bash
while getopts :abh opt
do case "$opt" in... (2 Replies)
Discussion started by: linuxkid
2 Replies
7. Shell Programming and Scripting
Hi everyone
I want to know how can we pass multiple argument in getopts
suppose
PARAMS="abcd"
while getopts ${PARMS} FLAG
do
case ${FLAG} in
(a)
(b)
(c)
(d)
esac (6 Replies)
Discussion started by: aishsimplesweet
6 Replies
8. Shell Programming and Scripting
In the below code
while getopts :rfw:d:s:a: options
do
case "$options" in
r) echo reverse;;
f) echo forward;;
w) window=$OPTARG;;
d) duration=$OPTARG;;
s) search=$OPTARG;;
a) value=$OPTARG;;
*) help; exit;;
esac
done
... (2 Replies)
Discussion started by: Amutha
2 Replies
9. Shell Programming and Scripting
Hi, I got some error when I try to write content from file store into array then for each word that separate by space use identify function to display image information.here is my code
#!/usr/bin/perl -w
open(FILE,'transfer_file_perl.txt') or die "$!";
my $line = <FILE>;#because it is one... (2 Replies)
Discussion started by: guidely
2 Replies
10. Shell Programming and Scripting
Hi,
I have written a script to take command line arguments using geopts.This is the code.
#!/bin/sh
# The usage of this script.
usage="Usage is $0"
usage="$usage "
usage="$usage "
usage="$usage "
# Use the getopt utility to set up the command line flags.
set -- `/usr/bin/getopt... (4 Replies)
Discussion started by: arijitsaha
4 Replies