You are not logged in.

#1 2013-03-14 13:33:24

simargl
Member
Registered: 2013-02-13
Posts: 51
Website

Problem with positional parameters (solved)

case "$1" in

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

esac

Problem is that -i (or -r) are picked as part of $PKG variable and I can't find solution for PKG to be $2 $3... and anything after that (not $1, because it is taken).

I hope you could understand this.

Last edited by simargl (2013-03-14 16:19:09)

Offline

#2 2013-03-14 13:36:53

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,033

Re: Problem with positional parameters (solved)

I, for one, cannot understand. Please clearly explain what you're trying to accomplish, show us example input and ouput, etc.

As a minor rant, not to be taken personally, it's really frustrating to me when a thread opens with a code/output example with no text introducing what I'm supposed to be looking at in the example. Please provide at least a small introduction so people know what you're talking about; we can't all read minds here.

Offline

#3 2013-03-14 13:36:59

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Problem with positional parameters (solved)

Have a look at getopts. It's in man Bash and a web search will pull up many examples.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#4 2013-03-14 15:52:25

WesleyDimble
Member
Registered: 2012-09-03
Posts: 18

Re: Problem with positional parameters (solved)

Are you looking for

shift

?

Offline

#5 2013-03-14 16:07:11

simargl
Member
Registered: 2013-02-13
Posts: 51
Website

Re: Problem with positional parameters (solved)

Thanks for your comments,


What I want is for example type:

spkg -i NAME1 NAME2 NAME3...  (spkg is script name)

and that this part "NAME1 NAME2 NAME3..." be variable PKG. Instead currently whole "-i NAME1 NAME2 NAME3... " is considered as PKG.

-i is position parameter $1 as it should, but how to avoid including it into $PKG. Something that says $2...

Offline

#6 2013-03-14 16:18:48

simargl
Member
Registered: 2013-02-13
Posts: 51
Website

Re: Problem with positional parameters (solved)

WesleyDimble wrote:

Are you looking for

shift

?

Wow.. with just adding "shift 1" it now works. Thanks man! smile

Last edited by simargl (2013-03-14 16:30:52)

Offline

Board footer

Powered by FluxBB