Re: bash usage.
> 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.
> # Demonstrate use of "mountpoint" in a script to determine
> # whether a directory has a device mounted on it.
> if [ mountpoint $WorkingDirectory ]
> echo A volume is mounted on $WorkingDirectory.
> echo Nothing mounted on $WorkingDirectory.
> 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 ] ?
write it like this:
if mountpoint $WorkingDirectory; then
echo A Volume is mounted on $WorkingDirectory.
echo Nothing mounted on $WorkingDirectory.
The "[" is actually a command (usually implemented by the shell itself)
that has its own expression syntax. See man test(1) for details.