Hello all I'm new here. I searched the web but couldn't find an answer to the following. Consider this very simple for loop.

Code:

for param in $1 $2; do echo "The parameters you gave are: "$paramdone

Now if I run this script with two parameters it works perfectly. What I don't understand is when I run the script with only one parameter it still works. It will only execute the for loop once. Call me crazy but I thought for sure it would error out because $2 is unsigned. What is going on here? Is bash smart enough to drop $2 from the list because it doesn't exist? Or is this bad coding practice? I wan't my script to work on many different computers so I don't want any anomalous behavior.

Sorry if this is a silly question or if I am missing something obvious. I am new to bash and linux in general. Thx for the replies in advance!

Who is online

Users browsing this forum: No registered users and 16 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum