On 02/25/2015 02:09 AM, James McMechan wrote: > Is there some reason you don't want to use the --output option? not in posix? > > # df / --output=avail > Avail > 10291956
1) Not in posix 2) Not yet implemented in toybox (because nothing I've tried uses it, so I'd be adding a dependency on an oddball feature). 3) Still not scriptable. It doesn't just produce the output, it produces a _label_ and the output, meaning I still have to run that through "tail" or something to get the numeric field isolated in a usable way I can do comparisons on. There's a marvelous book called "the unix philosophy" by mike gancarz that talks about output intended for humans vs output intended to be processed by other tools. A scriptable tool is one where you can do: echo $(( $(wc -l < blah) * 3)) If it's scriptable, the output of one tool is naturally the input to another. Admittedly this can be annoying to use from the command line such as the way "ls" with no arguments will produce no output when run in an empty directory. But the _reason_ for that is so "for i in $(ls); do blah $i; done" doesn't have to filter the ls output to use it in a script. That's why /proc/mounts doesn't have a line of field names, so you don't have to filter that out when processing it. It's also why the newer sysfs has the "one value per file" rule, so you don't have to parse values like you do in proc. stat is scriptable: if I go "stat -fc %a /" I get a number, by itself. (If block sizes were constant across filesystems I'd be able to stop there, but I have to do echo $(($(stat -fc "%a*%S" /run))) because %a gives me a block count, %S gives me the units, and the shell's $(( )) operator multiplies the two values together. Since -c is an output format with escapes I can have it supply the * operator, otherwise I'd have to do something like: echo $(( $(stat -fc %a /run)*$(stat -fc %S /run) )) At which point you start assigning values to shell variables... but still, I can get the value I want by itself, without having to chop it out of a larger display that could change which field is which in a random upgrade because they people making the pretty output decided something else looked better and now version skew broke my screen-scraping script. Rob _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
