Re: bash usage.
On Wed, Oct 25, 2017 at 05:39:35PM -0700, peter@easthope.ca wrote:
>
> According to 'man mountpoint', it returns 0 if something is mounted.
> So why the complaint from
> if [ mountpoint $WorkingDirectory ] ?
>
The return status is seen by the shell as a numeric. It is not coerced
to a boolean (like Perl or Python would do). Try this instead:
#!/bin/bash
# Demonstrate use of "mountpoint" in a script to determine
# whether a directory has a device mounted on it.
#
WorkingDirectory=/home/peter/testdir
mountpoint -q $WorkingDirectory
if [[ $? = 0 ]]
then
echo A volume is mounted on $WorkingDirectory.
else
echo Nothing mounted on $WorkingDirectory.
fi
--
Roberto C. Sánchez
Reply to: