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?!
$@
gets expanded, you should quote it then. – joH1 Jan 28 '18 at 09:44