On 07/19/2017 08:29 AM, Nellis, Kenneth wrote: > From: Steeve McCauley >> I can't believe I'd never thought of reordering output columns like this. >> FWIW, I agree that another option should be used to prevent issues with >> backward compatibility. >> >> $ echo 1,2,3,4,5,6 | cut -d, -f3,5,2 >> 2,3,5 >> >> $ echo 1,2,3,4,5,6 | cut -d, -f3,5,2 -o >> 3,5,2
Unfortunately, it takes time to add an option, and then for that addition to percolate into the pre-built binaries of all the distros that you use. In the meantime, you can already use awk to get the behavior you want today. And since awk is already portable and required by POSIX to be able to reorder output fields, it's that much more of a burden to justify adding a feature to cut (adding a feature is easy if it is easy to show that no other existing tools can fill the gap, but a one-line awk program doesn't feel like no other tools being able to fill the gap). Adding a new feature to GNU Coreutils is also easier to do if you can find someone else (like BSD) that already has the feature - but to my knowledge, no common 'cut -o' exists in other major distributions. > In addition, so that scripts can work across platforms, I (strongly) > recommend > that a cut-specific environment variable be defined to allow specifying the > field ordering behavior. In that way my QNX 4 script (whose cut would balk at > the -o option) would work with Gnu. One possibility: > > CUT_OPTIONS=-o Absolutely not. We have already learned from experience that environment variables that modify core program functionality, especially NEW environment variables that are not already accounted for in old scripts, tend to break old scripts. If you want a different default, our recommended approach is to write a shell script wrapper installed earlier on your $PATH, rather than abusing environment variables for everyone. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature