2 ms·
Word splitting is the difference between $ var='my program.py' $ python $var and $ python "$var" You need double quotes to protect against word
by chubot 9y ago
Word splitting is the difference between
$ var='my program.py'
$ python $var
and
$ python "$var"
You need double quotes to protect against word splitting. Almost all shell tutorials guides hammer this point home repeatedly, because if you omit double quotes, it works most of the time, and then blows up with incomprehensible error messages when you have spaces.
If you have a filename with spaces, like "my program.py", then python would be invoked with TWO arguments in the first case ["my", "program.py"].
But it will be invoked with single argument in the second case ["my program.py"], which is the correct thing.
I talk about how word splitting is really a hack around the historical lack of arrays in bash here:
"Thirteen Incorrect Ways and Two Awkward Ways to Use Arrays"
http://www.oilshell.org/blog/2016/11/06.html http://www.oilshell.org/blog/2016/11/06.html