getopt invalid option selection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getopt invalid option selection
# 1  
Old 12-20-2010
getopt invalid option selection

What is the significance of the *) and ?) in the below code.
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;;
   ?) echo "$OPTARG is an invalid option";
      my_exit 1;;
   esac
done

As i believe the ?) will do the invalid option . What could be the value *) will take as per getopt command???

Thanks
posix
# 2  
Old 12-20-2010
In the case of getopts, no difference as ? matches one character, and * matches any number of characters.

Each option with getopts is only one character, so ? and * would both match an "invalid" option

However:
Code:
A=abc
case "$A" in
  ?) echo Question Mark;;
  *) echo Asterisk
esac

Output:
Asterisk

Code:
A=a
case "$A" in
  ?) echo Question Mark;;
  *) echo Asterisk
esac

Output: Question Mark

# 3  
Old 12-20-2010
R0H0N
# 4  
Old 12-20-2010
Not a big getopts fan since it limits you to only have one arguement
per character therefore I like using long argument names, which allows
you do something like this:

In addition, if you want you can add code in the *) section if you want
to print invalid options or ignore them. No need to worry about what ?
mark does.


Code:
 
while [ $# -gt 0 ]
do
 
case $1 in
         -+([bB]*(lock_count|LOCK_COUNT)))
          shift
          let block_count=$1
          ;;
         -+([lL]*(ist|IST)))
             let list=1
              ;;
        -+([hH]*(elp|ELP)))
            usage
            return 0;;
         *)
           shift ;;
esac
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Adding another option to getopt

I am trying to code for the addition of a new argument to the command line, the option D to a code that already has ABC (below). When I use make to compile it, it displays: invalid option --D. I did define the global d variable, as well as initialized it inside the main function of the C code. I... (9 Replies)
Discussion started by: Alabama
9 Replies

3. UNIX for Dummies Questions & Answers

Invalid option errors running shell script

The script below fails with the following error messages: gzip: invalid option -- 'w' Try `gzip --help' for more information. mysqldump: Got errno 32 on write cp: invalid option -- 'w' Try `cp --help' for more information. rm: invalid option -- 'w' Try `rm --help' for more information. ... (1 Reply)
Discussion started by: ANNACTION
1 Replies

4. HP-UX

top -l 1 invalid option.

Hi, I am using below command to get the High CPU Utilization. top -l 1| awk ‘/CPU usage/ {print $12, $13}’ I am getting below error. ksh: 1: parameter not set top: illegal option -- l Usage: top Usage: awk ... Could you please suggest the appropriate solution. ... (3 Replies)
Discussion started by: wahab
3 Replies

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

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

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

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

9. Solaris

ps: 65535 is an invalid non-numeric argument for -p option

I want to figure out what is the reason of error message I have in Solaris 10. Why Solaris 10 dosn't recognize 65535? ps: 65535 is an invalid non-numeric argument for -p option usage: ps 'format' is one or more of: Thank you (5 Replies)
Discussion started by: gogogo
5 Replies

10. 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
Login or Register to Ask a Question