0

I am trying to display the disk freespace to users when they login. Basically the output of df -h. I added this to .bash:

  echo -ne '\e[0;34m'"Disk: \e[m"$(df -h)"\n"

It works fine & auto displays this on shell login but the problem is the output is cramped up. The column format is not preserved. It appears like this:

Filesystem 1024-blocks Used Available Capacity Mounted on /dev/sda6 468789752 4907272 440046272 2% / none 4 0 4 0% /sys/fs/cgroup udev 3785472 4 3785468 1% /run/shm none 102400 0 102400 0% /run/user /dev/sda1 184307 66572 104116 40% /boot

I want it to appear in the same format as if the user is running df -h. Any suggestions on how to modify my command to get a user friendly output? I tried using df -P | column -t also but it is still cramped.

Using Ubuntu server.

1 Answer 1

3

quotes are all messed up. This should work

 echo -ne '\e[0;34m' Disk: '\e[m' "$(df -h)" "\n"

Basically if you do

managemac3$ df=`df -h`
managemac3$ echo $df
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on /dev/disk0s2 233Gi 54Gi 179Gi 24% 14151768 46917672 23% / devfs 207Ki 207Ki 0Bi 100% 716 0 100% /dev map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
managemac3$ echo "$df"
Filesystem      Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
/dev/disk0s2   233Gi   54Gi  179Gi    24% 14151768 46917672   23%   /
devfs          207Ki  207Ki    0Bi   100%      716        0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%        0        0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%        0        0  100%   /home
managemac3$

THe quotes areound the variable keeps the formatting in check

You must log in to answer this question.