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 Thu 18 Dec 2014, 04:28
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 Posts_count  
Author Message
simargl

Joined: 11 Feb 2013
Posts: 572

PostPosted: Thu 14 Mar 2013, 08:56    Post_subject:  .  

.
Edited_times_total
Back to top
View user's profile Send_private_message Visit_website 
SFR


Joined: 26 Oct 2011
Posts: 1111

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:  

.
Edited_time_total
Back to top
View user's profile Send_private_message Visit_website 
seaside

Joined: 11 Apr 2007
Posts: 888

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:  

.
Edited_time_total
Back to top
View user's profile Send_private_message Visit_website 
seaside

Joined: 11 Apr 2007
Posts: 888

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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0754s ][ Queries: 11 (0.0221s) ][ GZIP on ]