« Another Email Account Milestone | Main | The Trials and Tribulations of Testing SMTP Authentication From Within Bash »

Cool Bash Trick I Didn't Know About

Usually, when I use a for loop in Bash, I do something like:

for USERNAME in $USERNAME_LIST

I found out today that you can also call a for loop without the "in" parameter and it will default to getting the input parameters that are passed to your script in the first place. So, if you want to be able to run your script as:

./my_script.sh username1 username2 username3

each of those usernames can be processed with a for like like:

for USERNAME
do
     echo $USERNAME #Just echo it back out for debugging purposes
done

Common knowledge, I'm sure, but it's new to me and came in super handy today.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on September 5, 2007 3:44 PM.

The previous post in this blog was Another Email Account Milestone.

The next post in this blog is The Trials and Tribulations of Testing SMTP Authentication From Within Bash.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34