What's the best way to check if a volume is mounted in a Bash script?
What I'd really like is a method that I can use like this:
if <something is mounted at /mnt/foo>
then
<Do some stuff>
else
<Do some different stuff>
fi
bashlinuxmount
What's the best way to check if a volume is mounted in a Bash script?
What I'd really like is a method that I can use like this:
if <something is mounted at /mnt/foo>
then
<Do some stuff>
else
<Do some different stuff>
fi
Best Answer
Avoid using
/etc/mtab
because it may be inconsistent.Avoid piping
mount
because it needn't be that complicated.Simply:
(The space after the
/mnt/foo
is to avoid matching e.g./mnt/foo-bar
.)