[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

bash usage.



PROBLEM
Given a storage device, /dev/GRN, and mount point, /home/peter/testdir/, 
determine in a shell script whether /dev/GRN is mounted or something is 
mounted on /home/peter/testdir/.

ATTEMPTED SOLUTION
Create testdir and execute this script.

#!/bin/bash
# Demonstrate use of "mountpoint" in a script to determine 
# whether a directory has a device mounted on it.
#
WorkingDirectory=/home/peter/testdir
if [ mountpoint $WorkingDirectory ]
  then
    echo A volume is mounted on $WorkingDirectory.
else
    echo Nothing mounted on $WorkingDirectory.
fi

This is my result.
$ ./testscript
./testscript: line 6: [: mountpoint: unary operator expected
Nothing mounted on /home/peter/testdir.

According to 'man mountpoint', it returns 0 if something is mounted.  
So why the complaint from 
  if [ mountpoint $WorkingDirectory ] ?
  
Thanks,             ... Peter E.


-- 

123456789 123456789 123456789 123456789 123456789 123456789 123456789
Tel: +1 360 639 0202                      Pender Is.: +1 250 629 3757
http://easthope.ca/Peter.html              Bcc: peter at easthope. ca


Reply to: