Timeline for answer to Why does a backslash at the end of the line place undue whitespace? by AdminBee
Current License: CC BY-SA 4.0
Post Revisions
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 18, 2023 at 17:56 | comment | added | Stéphane Chazelas |
@PeterCordes, that page says the same thing as I did above. There is no word splitting here, because there's none of the expansions that word splitting applies to. Word splitting is a separate step that is done long after the shell code is tokenised (on whitespace, ;, |...) and parsed (into simple commands, complex structures, etc...).
|
|
| Nov 18, 2023 at 15:37 | comment | added | Peter Cordes | @StéphaneChazelas: The bash man page (man7.org/linux/man-pages/man1/bash.1.html#EXPANSION) uses the term "word splitting" for the tokenization step bash performs after some expansion steps. I didn't realize it had a different meaning in contexts outside of bash. | |
| Nov 18, 2023 at 13:24 | comment | added | ilkkachu |
@PeterCordes, To put Stéphane's point in an example, in heirloom-sh, IFS=l; echo hello prints he o and you need to quote "hello" to protect it from splitting. The distinction is also important wrt. other syntax elements, like quotes. People tend to try to put to quotes inside variables and then are surprised it doesn't do what they want. (e.g. s='"foo bar" doo'; printf "%s\n" $s prints three lines and literal double-quotes.) Of course it doesn't work because word splitting is not the same as syntax processing.
|
|
| Nov 18, 2023 at 10:57 | comment | added | Stéphane Chazelas |
@PeterCordes, there's no word splitting here, just syntax tokenisation, only the Bourne shell did word (IFS) splitting on (some) literal words. Other Bourne like shells only do it on the result of expansions ($param, $((arith)), $(cmd)) as required by POSIX (while POSIX prohibits the splitting behaviour of the Bourne shell).
|
|
| Nov 17, 2023 at 22:07 | comment | added | Peter Cordes | @StéphaneChazelas: A more precise way to say what this answer meant is: "The leading whitespace isn't removed before word-splitting, unlike the single newline that's escaped by a backslash." | |
| Nov 16, 2023 at 16:55 | comment | added | Stéphane Chazelas |
The spacing is autoremoved. Those blank characters are part of the shell syntax to delimit arguments that are to be passed to the command, they are not included in those arguments. xtrace shows spaces between those argument because xtrace shows shell code that could be used to run the same command, and one space separator is the shortest and simplest way to do it.
|
|
| Nov 16, 2023 at 13:53 | comment | added | rhuanpk | Nice, your explanation was good and I understood. Is there a way to do this while keeping the tabs? | |
| Nov 16, 2023 at 13:05 | history | answered | AdminBee | CC BY-SA 4.0 |