2

This question already has an answer here:

Using $@ instead of $* would preserve quoting. Consider the following script:

#!/bin/bash
# Test.sh
for arg in $@
do
echo "I found the argument $arg"
done

./Test.sh "One Two Three"

I reach the output below:

I found the argument One
I found the argument Two
I found the argument Three

I don't understand why the For loop is executed three times?!

marked as duplicate by muru, cas, Community Jan 28 '18 at 9:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • The loop is executed several times because $@ gets expanded, you should quote it then. – joH1 Jan 28 '18 at 9:44

Browse other questions tagged or ask your own question.