Re: Easiest Way in Perl to check Whether a Disk is Mounted
[email protected] (Will Mengarini via beginners) Wed, 5 Jun 2024 14:42:18 -0700
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
* Martin McCormick <[email protected]> [24-06/01=Sa 09:25 -0500]: > [...] determine whether a file system is mounted such as > $ mount |grep horseradish > [...] I think perl -e 'print grep m[/horseradish],`mount`' is hard to beat for its simplicity. Note I'm using Perl's built-in grep; there's no need to run the system's grep. You can code something like -------------------------------- if( grep m[/horseradish],`mount` ){ useMountedHorseradish(); }else{ dealWithUnmountedHorseradish(); } -------------------------------- because Perl's grep will return an empty string if 'horseradish' isn't found in `mount`, and an empty string is logically false, whereas any nonempty string is logically true.