Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 27 Aug 2014, 23:44
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
.
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
simargl

Joined: 11 Feb 2013
Posts: 572

PostPosted: Thu 14 Mar 2013, 08:56    Post subject:  .  

.
Last edited by simargl on Sun 01 Sep 2013, 12:09; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1063

PostPosted: Thu 14 Mar 2013, 10:27    Post subject: Re: Problem with positional parameters  

How about this:
Code:
case "$1" in

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

esac

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
simargl

Joined: 11 Feb 2013
Posts: 572

PostPosted: Thu 14 Mar 2013, 12:18    Post subject:  

.
Last edited by simargl on Sun 01 Sep 2013, 10:41; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Thu 14 Mar 2013, 12:37    Post subject:  

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")
Back to top
View user's profile Send private message 
simargl

Joined: 11 Feb 2013
Posts: 572

PostPosted: Thu 14 Mar 2013, 13:23    Post subject:  

.
Last edited by simargl on Sun 01 Sep 2013, 10:41; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Thu 14 Mar 2013, 17:01    Post subject:  

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
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0479s ][ Queries: 12 (0.0060s) ][ GZIP on ]