Solved

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

Posted on 2011-02-17
3
577 Views
Last Modified: 2013-12-26
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
Comment
Question by:nocturn4l
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 34915580
while [ $# -gt 0 ] ; do
  echo $*
  shift
done
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 34915594
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
 

Author Closing Comment

by:nocturn4l
ID: 34915624
life saver
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now