Sponsored Content
Top Forums Shell Programming and Scripting Identify problem with while getopts Post 302978469 by SkySmart on Sunday 31st of July 2016 12:48:18 AM
Old 07-31-2016
Quote:
Originally Posted by Don Cragun
It is not! According to the standards, options must be specified on the command line BEFORE operands.

Furthermore, I have no idea why you have so many colons in the first argument passed to getopts??? Are you trying to say that you will allow up to six -: :_option_argument options??? You don't have a : choice in your case statement and you don't need to specify an option more than once in that operand even if more than one of those options are allowed.

I would try to write code that might work for you, but I have no idea what you are trying to do. The Usage statement printed by your code when things go wrong indicate that absolutely no options are allowed.

The getopts man page on your system or the man page for your shell on your system may supply an option (or an environment variable setting) that will allow you to violate POSIX rules and allow you to process command-line arguments with options after operands by reordering your command line. My system doesn't allow that without lots of extra abnormal argument processing and I won't help you do that because I believe that any new application written to put options after operands is fundamentally broken. (The only exceptions to this are utilities like compilers and linkers that need to apply certain options to certain groups of operands and different options to different groups of operands. That does not seem to be the case for what you are trying to do.)

And, what is the use of having "options" -i optional_string1include:optional_string2 and -e optional_string3exclude:optional_string4 if you script is going to fail if both of those options are not specified on the command line? If an option has to be specified, by definition, it is not an option! Did you just forget to supply default values for these options, or are they just additional required operands and you are trying to say that the order of those operands in relation to other required operands is unspecified??? (If this is what you're saying, I personally believe this is a horrendous human factors decision.)
i apologize for not being clear.

currently, there are 4 ways to run my script.

one is without any of the -i or -e options being passed to it
second is if just the -i is passed to it
third is if just the -e is pass to it
fourth is if both -i and -e are passed to the script

all im trying to do is account for those 4 scenarios using getopts.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with getopts

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

Problem in getopts

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

problem with getopts

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

getopts problem

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

using getopts

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

getopts problem

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

getopts problem

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

getopts - optional and problem to display help

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

Identify function image magick problem - perl

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

problem with getopts

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
volcopy(1M)						  System Administration Commands					       volcopy(1M)

NAME
volcopy - make an image copy of file system SYNOPSIS
volcopy [-F FSType] [-V] [generic_options] [-o FSType-specific_options] operands DESCRIPTION
volcopy makes a literal copy of the file system. This command may not be supported for all FSTypes. OPTIONS
The following options are supported: -F FSType Specify the FSType on which to operate. The FSType should either be specified here or be determinable from /etc/vfstab by matching the operands with an entry in the table. Otherwise, the default file system type specified in /etc/default/fs will be used. -V Echo the complete command line, but do not execute the command. The command line is generated by using the options and arguments provided by the user and adding to them information derived from /etc/vfstab. This option should be used to verify and validate the command line. generic_options Options that are commonly supported by most FSType-specific command modules. The following options are available: -a Require the operator to respond "yes" or "no" instead of simply waiting ten seconds before the copy is made. -s (Default) Invoke the DEL if wrong verification sequence. -o FSType-specific_options Specify FSType-specific options in a comma separated (without spaces) list of suboptions and keyword- attribute pairs for interpretation by the FSType-specific module of the command. OPERANDS
The following operands are supported: operands generally include the device and volume names and are file system specific. A detailed description of the operands can be found on the FSType-specific man pages of volcopy. EXIT STATUS
The following exit values are returned: 0 Successful file system copy 1 An error has occurred. FILES
/etc/vfstab list of default parameters for each file system /etc/default/fs default local file system type. Default values can be set for the following flags in /etc/default/fs. For example: LOCAL=ufs. LOCAL: The default partition for a command if no FSType is specified. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
labelit(1M), vfstab(4), attributes(5) Manual pages for the FSType-specific modules of volcopy. SunOS 5.11 20 Mar 1995 volcopy(1M)
All times are GMT -4. The time now is 07:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy