Web lists-archives.com

Re: bash usage.




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Nov 05, 2017 at 08:31:00AM +1100, David Margerison wrote:
> On 5 November 2017 at 04:55,  <peter@xxxxxxxxxxx> wrote:
> 
> > What about checking whether the
> > filesystem of a specific device is mounted at that directory?  Can
> > that be checked easily?
> 
> It can be done by inspecting the output of the 'mount' command.
> But keep in mind that the detail of this output may not be stable
> between versions of mount, or other factors that might change
> its content, such as releases of operating systems.
> 
> Demo example from an interactive bash command line on this PC:
> 
> $ devname=/dev/sda6 ; dirname=/mnt/p/A ; if mount | grep -q --
> "$devname on $dirname" ; then echo "$devname is mounted on $dirname" ;
> fi
> /dev/sda6 is mounted on /mnt/p/A

Note that the mount(8) man page recommends findmnt(8) for script
usage. Findmnt is util-linux, so whether you want to use it or
not will depend a bit on your portability needs.

Parsing mount output robustly is, of course, always a good exercise.

Cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAln+yTAACgkQBcgs9XrR2kbLxQCbBYJ24P3cpSDfCv8UpCuosZTj
+rgAnj9KITg3S+ulgtwicWTDs0mmC0po
=MHdd
-----END PGP SIGNATURE-----