[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

Command Line Arguments like $# or $1.. how to increment?- Bourne Shell

Let's say the script is called test.sh

and i run it so it's like "test.sh a b c d e f"

I'm trying to print it so it prints something like
a b c d e f
b c d e f
c d e f
etc

I'm trying something like maybe incrementing $1.. so i can do something like

num=`expr $1 + 1`
echo num

but that isn't working... i'm still not sure how i can code this yet, but I'm thinking if I can increment $1, i can figure something out.. is there some way I can do this?

I know of the $# and $@ but I don't think it helps very much.. i'm hoping someone can push me in the right direction
0
nocturn4l
Asked:
nocturn4l
2 Solutions
 
ozoCommented:
while [ $# -gt 0 ] ; do
  echo $*
  shift
done
0
 
woolmilkporcCommented:
Hi,

you can use "shift", which will drop $1, make $2 to $1, $3 to $2 etc.

There is also "shift 2", "shift 3" etc.

wmp

0
 
nocturn4lAuthor Commented:
life saver
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now