I have a shell script that prints the first argument passed to it in the command line. I was experimenting with $1
and "$1"
. Interestingly to me, when I pass "John Doe" I get different outputs.
hw Version1
#!/bin/bash
printf "Hello %s\n" $1
Result is the following. Seems like it loops through strings separated by space:
$ hw "John Doe"
Hello John
Hello Doe
hw Version2
#!/bin/bash
printf "Hello %s\n" "$1"
Result is:
$ hw "John Doe"
Hello John Doe
what is the difference between $1
and "$1"
when the argument in the command line is something like "string1 string2 ... stringn"
?