Reputation: 6690
This is my shell script-
if ! options=$(getopt -o : -l along:,blong:,clong: -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi
set -- $options
while [ $# -gt 0 ]
do
case $1 in
--along) echo "--along selected :: $2" ;;
--blong) echo "--blong selected :: $2" ;;
--clong) echo "--clong selected :: $2" ;;
esac
shift
done
when i run the script i get the following output-
./test.sh --along hi --blong hello --clong bye
--along selected :: 'hi'
--blong selected :: 'hello'
--clong selected :: 'bye'
The problem is I don't want to display the arguments with single quotes ('hi', 'hello', 'bye'). What should I do to get rid of those quotes?
Upvotes: 1
Views: 2892
Reputation: 7521
Use the option -u
or --unquoted
for getopt, i.e.
if ! options=$(getopt -u -o : -l along:,blong:,clong: -- "$@")
The manpage of getopt says for -u
:
Do not quote the output. Note that whitespace and special (shell-dependent) characters can cause havoc in this mode (like they do with other getopt(1) implementations).
Upvotes: 6