.
Re: Problem with positional parameters
How about this:
Greetings!
Code: Select all
case "$1" in
install|-i)
shift
PKG="$@"
install_package ;;
remove|-r)
shift
PKG="$@"
remove_package ;;
esac
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
simargl,simargl wrote:I know that, but needed was $2 and everything after ("$@" would take $1 also), and Yes sfr solved it!seaside wrote:PKG="$2" will set the second command line parameter.
"$@" means the entire command line arguments.
Yes, I see now, you wanted to process an unknown quantity of command line parameters (packages) after determining the first parameter (-i or -r). "Shift" commnand is the way to do that as it allows a repeated use of $1 in a while loop.
Cheers,
s