(GNU) df gives multiline output even when piped
When 'df' program encounters "long" device or mountpoint names, it makes the terminal output prettier by splitting such lines into two and space-padding the output.
However, and many scripts historically depended on it, 'df' produces a single line per filesystem when piped (to grep, awk or whatever). This works with both Solaris and Linux (GNU?) df variants.
However, the /usr/gnu/bin/df in OI_148a LiveUSB lacks this feature:
root@openindiana:~# df -k /a
Filesystem 1K-blocks Used Available Use% Mounted on
16717979 2968243 13749736 18% /a
root@openindiana:~# df -k | grep openindiana
This is a bug and should be fixed - it can break an indeterminate number of scripts and programs which rely on parsing the 'df' output.
Updated by Julian Wiesener about 10 years ago
- Category set to 10
- Assignee set to OI SFW
Workarround: Do not use GNU df for your shell scripts
root@laphroaig:~# /usr/gnu/bin/df -k | grep -i long_long
root@laphroaig:~# /usr/bin/df -k | grep -i long_long
rpool/filesystem_with_long_long_long_long_long_long_long_long_name 76382208 21 24797798 1% /mnt
Updated by Jim Klimov about 10 years ago
Workaround is relatively suitable, except:
1) Many (legacy/packaged) scripts I've encountered and written rely on system PATH.
If OI sets by default that GNU/bin would be before system /usr/bin, and those utilities don't work properly, it is an issue. Changing all these scripts on each installation (or changing the /etc/profile and wherever else the GNU path is prepended) is not practical.
2) In this particular case, the scripts that broke for me are portable between RHEL and (Open)Solaris, and in both platforms the default "df" worked properly. I'm pretty sure that Linux "df" is a GNU "df", so I view that change in behavior as a regression/incompatibility/whatever.
Updated by Ken Mays over 9 years ago
- Status changed from New to Resolved
kmays ~ (spiritworld): df --version
df (GNU coreutils) 8.5
kmays ~ (spiritworld): df -k |grep spirit
GNU df is within specs. Possibly, upgrade later.