Skip to main content
Note about spaces in file system names
Source Link
Jonathan Leffler
  • 759.1k
  • 145
  • 961
  • 1.3k

You'll simplify your life by making effective use of single quotes as well as double quotes:

mountPoint="`df -h | grep $pth | tr -s ' ' | cut -d' ' -f6`"

The first step in debugging this is to remove the cut command and see what it produces:

mountPoint="`df -h | grep $pth | tr -s ' '`"
echo $mountPoint

Does it still print 6 (or more) columns?

Note that if you misspell the argument to the command, then the grep will pass nothing through to the cut.

On my machine (a Mac), I get the output from df -h:

Filesystem      Size   Used  Avail Capacity  Mounted on
/dev/disk0s2   465Gi  189Gi  277Gi    41%    /
devfs          111Ki  111Ki    0Bi   100%    /dev
map -hosts       0Bi    0Bi    0Bi   100%    /net
map auto_home    0Bi    0Bi    0Bi   100%    /home
/dev/disk1s1   1.8Gi  8.8Mi  1.8Gi     1%    /Volumes/BLACKBERRY

Note that some of the file system names have spaces in them. It is unlikely to be a factor in your problem, but it could throw things off (the mount point is then field 7).

You'll simplify your life by making effective use of single quotes as well as double quotes:

mountPoint="`df -h | grep $pth | tr -s ' ' | cut -d' ' -f6`"

The first step in debugging this is to remove the cut command and see what it produces:

mountPoint="`df -h | grep $pth | tr -s ' '`"
echo $mountPoint

Does it still print 6 (or more) columns?

Note that if you misspell the argument to the command, then the grep will pass nothing through to the cut.

You'll simplify your life by making effective use of single quotes as well as double quotes:

mountPoint="`df -h | grep $pth | tr -s ' ' | cut -d' ' -f6`"

The first step in debugging this is to remove the cut command and see what it produces:

mountPoint="`df -h | grep $pth | tr -s ' '`"
echo $mountPoint

Does it still print 6 (or more) columns?

Note that if you misspell the argument to the command, then the grep will pass nothing through to the cut.

On my machine (a Mac), I get the output from df -h:

Filesystem      Size   Used  Avail Capacity  Mounted on
/dev/disk0s2   465Gi  189Gi  277Gi    41%    /
devfs          111Ki  111Ki    0Bi   100%    /dev
map -hosts       0Bi    0Bi    0Bi   100%    /net
map auto_home    0Bi    0Bi    0Bi   100%    /home
/dev/disk1s1   1.8Gi  8.8Mi  1.8Gi     1%    /Volumes/BLACKBERRY

Note that some of the file system names have spaces in them. It is unlikely to be a factor in your problem, but it could throw things off (the mount point is then field 7).

Source Link
Jonathan Leffler
  • 759.1k
  • 145
  • 961
  • 1.3k

You'll simplify your life by making effective use of single quotes as well as double quotes:

mountPoint="`df -h | grep $pth | tr -s ' ' | cut -d' ' -f6`"

The first step in debugging this is to remove the cut command and see what it produces:

mountPoint="`df -h | grep $pth | tr -s ' '`"
echo $mountPoint

Does it still print 6 (or more) columns?

Note that if you misspell the argument to the command, then the grep will pass nothing through to the cut.