On 30/01/16 15:45, Christoph Anton Mitterer wrote: > Hey. > > I've also just stumbled over this... while the idea is nice in > principle, I think it's quite dangerous as well... even if behaviour is > preserved when output goes to a terminal. > > a) The quotation alone doesn't necessarily help with copy&paste, > depending on where you paste. > > b) When the pasted content is actually further to be processed by e.g. > old scripts (which expect perhaps one *unquoted* name per line) things > will fail. > > c) We now have what you see is NOT what you get [when stdout is not a > terminal] > People do use ls in all it's variations in countless of scripts, and > they build up their scripts by first trying it out on the terminal to > see what they get is what they want to have in the script. > But now, what they get is different in both. > And the change isn't necessarily one that get's noticed, but it still > may lead to all kinds of garbage, wrong files being deleted and so on. > > Consider a user writes a script that shall deleted all files from > 2012... a stupid solution may be something like: > rm -f "$( ls -1l | grep <some pattern that matches the date column> | sed > "some pattern that removes everything up the filename" | xargs )" > On the terminal this may give proper: > rm -f 'file with spaces mythesis.pdf' > in the script this would give > rm -f file with spaces mythesis.pdf
ls output really isn't amenable to further processing. That's what find(1) is focused on. Though I see what you're saying. Let's try and force your example into something concrete. You're saying that people might assume files are always quoted, but I'm explicitly adding the --quoting option below to see if users did notice to do that, whether further processing of ls is valid anyway. # Very carefully format ls output for processing ls -ln --quoting=shell-escape --block-size=1 --time-style='+%m' | # Get rid of the first few space aligned fields while not # impacting consecutive spaces in a file name. sed 's/\([^ ]* \)\{4\}//; s/^ *[^ ]* //' | # Pick files in January grep ^01 | # Get the quoted file names cut -d' ' -f2- # Process them xargs ... Now this mostly works, right up until xargs, but that will only strip single quotes. It will not process $'\n' quoting that ls may also output. Also given the extreme awkwardness in the filtering above, users are really going to be and should be using find(1) instead. So yes you have a valid point, but it's quite a contrived situation. cheers, Pádraig.