I just noticed that on one of my machines (running Debian Sid) whenever I type ls
any file name with spaces has single quotes surrounding it.
I immediately checked my aliases, only to find them intact.
wyatt@debian630:~/testdir$ ls
'test 1.txt' test1.txt
wyatt@debian630:~/testdir$ alias
alias ls='ls --color=auto'
alias wget='wget --content-disposition'
wyatt@debian630:~/testdir$
Another test, with files containing single quotes in their names (also answering a request by jimmij):
wyatt@debian630:~/testdir$ ls
'test 1.txt' test1.txt 'thishasasinglequotehere'\''.txt'
wyatt@debian630:~/testdir$ touch "'test 1.txt'"
wyatt@debian630:~/testdir$ ls
''\''test 1.txt'\''' test1.txt
'test 1.txt' 'thishasasinglequotehere'\''.txt'
update with new coreutils-8.26 output (which is admittedly much less confusing, but still irritating to have by default). Thanks to Pádraig Brady for this printout:
$ ls
"'test 1.txt'" test1.txt
'test 1.txt' "thishasasinglequotehere'.txt"
$ ls -N
'test 1.txt' test1.txt
test 1.txt thishasasinglequotehere'.txt
Why is this happening? How do I stop it properly?
To be clear, I myself set ls to automatically color output. It just never put quotes around things before.
I'm running bash
and coreutils 8.25.
Any way to fix this without a recompile?
EDIT: Appears the coreutils developers chose) to break with the convention and make this the global default.
UPDATE - October 2017 - Debian Sid has re-enabled the shell escape quoting by default. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=877582
And at the bottom of the reply chain to the previous bug report, "the change was intentional and will remain." https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=813164#226
I thought this had already been settled, but apparently it was just reverted so that the "stable" Debian branch could keep its "feature freeze" while getting the other fixes, etc. from the newer version. So that's a shame (in my opinion).
UPDATE: April 2019: Just found a spurious bug report in PHP that was caused by this change to ls
. When you're confusing developers and generating false bug reports, I think it might be time to re-evaluate your changes.
Update: Android toybox ls
is now doing something similar to this but with backslashes instead of quotes. Using the -q option makes spaces render as 'question mark characters' (I have not checked what they are, since they're obviously not spaces), so the only fix I have found so far without rooting the device in question is to add this to a script and source it when launching a shell. This function makes ls
use columns if in a terminal and otherwise print one-per-line, while tricking ls
into printing spaces verbatim because it's running through a pipe.
ls() {
# only way I can stop ls from escaping with backslashes
if [ -t 1 ]; then
/system/bin/ls -C $@ |cat
else
/system/bin/ls $@ |cat
fi
}
ls
command.ls | cat
and see if it goes away. If I had a time machine, I would go back to Bell Labs ~1970 and try to convince Ken Thompson that allowing space in file and directory names is a bad idea. :-P'*'
. I guess I'll go around addingls
aliases to all my machines to get rid of it...QUOTING_STYLE=literal
rather than an alias. (I guess it's a matter of taste, but I prefer the variable.)