2

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?!

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

0 Answers0