LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   use getopt in shell script (https://www.linuxquestions.org/questions/linux-newbie-8/use-getopt-in-shell-script-933142/)

haiyuan_victor 03-07-2012 01:04 AM

use getopt in shell script
 
Hi,
I want to use getopt(1) to check the shell script's option and its' option arguments!
e.g.
test.sh --version|-V
test.sh --update {a | b}
when i type:
test.sh --up
it should prompt that it can not recognize --up this option, other than lack of option arguments
test.sh --update
it should prompt that it lacks of option arguments
i wrote this shell script:

#!/bin/bash

ARGS=`getopt -o ab:c:: -l a-long,b-long:,c-long:: -- "$@"`


but, when i input:
./test.sh --b-lo
it prompts that the --b-lo lacks of arguments, other than it can not recognize it

catkin 03-07-2012 11:33 PM

The error message from ./test.sh --b-lo is correct. --b-lo is an "unambiguous abbreviation" of the --b-long defined in your getopt command as requiring an option argument which is not present in ./test.sh --b-lo


All times are GMT -5. The time now is 04:28 PM.