.

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
simargl

.

#1 Post by simargl »

.
Last edited by simargl on Sun 01 Sep 2013, 16:09, edited 4 times in total.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

Re: Problem with positional parameters

#2 Post by SFR »

How about this:

Code: Select all

case "$1" in

  install|-i)
     shift
     PKG="$@"
     install_package ;;
   
  remove|-r)
     shift
     PKG="$@"
     remove_package ;;

esac
Greetings!
[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]

simargl

#3 Post by simargl »

.
Last edited by simargl on Sun 01 Sep 2013, 14:41, edited 1 time in total.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#4 Post by seaside »

simargl,

PKG="$2" will set the second command line parameter.
"$@" means the entire command line arguments.

Cheers,
s
(I guess you could mark this thread "Solved")

simargl

#5 Post by simargl »

.
Last edited by simargl on Sun 01 Sep 2013, 14:41, edited 1 time in total.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#6 Post by seaside »

simargl wrote:
seaside wrote:PKG="$2" will set the second command line parameter.
"$@" means the entire command line arguments.
I know that, but needed was $2 and everything after ("$@" would take $1 also), and Yes sfr solved it!
simargl,

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

Post Reply