Solved

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

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change the background and font colors in Notepad++ 5 155
OS Selection Menu 1 65
UNIX Script. Send email if failure 8 57
.dn property wont validate - Powershell 2 22
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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