3 ms·
> Bash cleans up extra spaces when writing to stdout unless you use variable quoting. Not really: echo $result Will evaluate to: echo node-0 Ready
by linkdd 5y ago
> Bash cleans up extra spaces when writing to stdout unless you use variable quoting.
Not really:
echo $result
Will evaluate to:
echo node-0 Ready <none> 3d v1.11.1
Which is the following argv array in C:
const char *argv = { "echo", "node-0", "Ready", "<none>", "3d", "v1.11.1" };
Then `echo` is a builtin command that prints argv[1:] separated by spaces.
Then:
echo "$result"
Evaluates to:
echo "node-0 Ready <none> 3d v1.11.1"
Which is the following argv array in C:
const char *argv = { "echo", "node-0 Ready <none> 3d v1.11.1" };
The spaces get cleaned up when parsing the command line, not when writing to stdout.
- galgalesh 5y agoCame here just to say that. It's such a beautiful case where a developer notices an issue in their mental model of how the tools work, changes their mental model to account for that issue, but as a result introduces a completely different bug in their mental model.
- teknopaul 5y agoSomeone need to add a comment to the page so the misconception does not spread. I would but Discuss does not like me.
- oshiar53-0 5y agoYes, and also glob expansion: msg="Configured search pattern: /usr/*" echo $msg # Configured search pattern: /usr/bin /usr/games /usr/lib /usr/lib64 ...