Script loop question

Oliver Marshall Oliver.Marshall at
Thu Nov 12 09:16:23 UTC 2009

Thanks for that. I've also just found the magic shift command which is superb (MS are you listening?). Using it like this;

# Loop until all parameters are used up
while [ "$1" != "" ]; do
    echo "Parameter 1 equals $1"
    echo "You now have $# positional parameters"

    # Shift all the parameters down by one


G2 Support
Network Support : Online Backups : Server Management

Twitter: g2support

-----Original Message-----
From: ubuntu-users-bounces at [mailto:ubuntu-users-bounces at] On Behalf Of Markus Schönhaber
Sent: 12 November 2009 09:13
To: ubuntu-users at
Subject: Re: Script loop question

Oliver Marshall:

> I have a script that takes an argument (a file name) and performs
> actions on that file. I want to mod the script so that i can pass, as
> arguments, multiple filenames and have the script perform the same
> set of commands on each file in turn, like this;
> ./ file1 file2 file3
> etc.
> I guess it's bringing the two parts of the loop and the arguments
> together to loop through each argument in turn, but that's where I
> get stuck.

for f in "$@"; do
  echo $f


ubuntu-users mailing list
ubuntu-users at
Modify settings or unsubscribe at:

More information about the ubuntu-users mailing list