Script loop question
Oliver Marshall
Oliver.Marshall at g2support.com
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
shift
done
--
G2 Support
Network Support : Online Backups : Server Management
Web: www.g2support.com
Twitter: g2support
Newsletter: www.g2support.com/newsletter
-----Original Message-----
From: ubuntu-users-bounces at lists.ubuntu.com [mailto:ubuntu-users-bounces at lists.ubuntu.com] On Behalf Of Markus Schönhaber
Sent: 12 November 2009 09:13
To: ubuntu-users at lists.ubuntu.com
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;
>
> ./filename.sh 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
done
--
Regards
mks
--
ubuntu-users mailing list
ubuntu-users at lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
More information about the ubuntu-users
mailing list