3 ms·
>> Let's first figure out what it means to work with whitespace properly What does it mean to work with whitespace properly? When commands are entered at the
by thesuperbigfrog 3y ago
>> Let's first figure out what it means to work with whitespace properly
What does it mean to work with whitespace properly?
When commands are entered at the command line and a shell is parsing, how do you distinguish between whitespace between commands, command parameters and switches, filenames that include whitespace characters, paths that include whitespace characters, etc. ?
It is a difficult question that does not have good answers.
- arp242 3y agoNot expanding whitespace on $var would be a huge improvement; shells like rc and zsh have been doing that since the early 90s and it's a huge improvement, so hardly a new innovation. Bash refuses to implement this even as an option because ... reasons? Significant chunks of bash are still written in K&R C today, so it's not exactly cutting edge... Autocompletion works well enough for doing things like "ls file with space": either just as "ls file<Tab>" or "ls 'file<Tab" (in zsh it picks up on a starting ' or " so you don't end up with loads of backslashes).
- teo_zero 3y agoOn the other hand, not splitting words at spaces during variable expansion would make impossible things like: OPTS="-a -b -c" foo $OPTS
- o11c 3y agoJust use an array. POSIX sh is a useless target, all serious shells support arbitrary arrays.
- arp242 3y agoUse $=opts in zsh for explicit splitting. Better would to be use an array though: 'opts=(-a -b -c)' and then just 'foo $opts'. I'm not sure about rc on this as I'm not too familiar with rc, but I'd be surprised if there wasn't a way to do this.