Solved

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

Posted on 2011-02-17
3
580 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

816 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

13 Experts available now in Live!

Get 1:1 Help Now