I am new at scripting ... I can do very basic stuff, but now I need a hand.I have a local filesystem that only will be mounted when I need to do a backup.I'm starting with this.#!/bin/bashexport MOUNT=/myfilesystemif grep -qs $MOUNT /proc/mounts; then  echo It's mounted.else  echo It's not mounted.; then  mount $MOUNT;fiAs I said, I'm very basic at scripting. I heard that you can check the status of the mount command by looking at the return codes.RETURN CODES       mount has the following return codes (the bits can be ORed):       0      success       1      incorrect invocation or permissions       2      system error (out of memory, cannot fork, no more loop devices)       4      internal mount bug       8      user interrupt       16     problems writing or locking /etc/mtab       32     mount failure       64     some mount succeededI don't know how to check that. Any guidance?
How to check if a filesystem is mounted with a script
bash;shell script;mount
You can check the status code of mount, and most well written executables, with the shell special parameter ?.From man bash:?  Expands to the exit status of the most recently executed foreground pipeline.After you run the mount command, immediately executing echo $? will print the status code from the previous command.# mount /dev/dvd1 /mnt  mount: no medium found on /dev/sr0# echo $?  32Not all executables have well defined status codes. At a minimum, it should exit with a success (0) or failure (1) code, but that's not always the case.To expand on (and correct) your example script, I added a nested if construct for clarity. It's not the only way to test the status code and perform an action, but it's the easiest to read when learning.#!/bin/bashmount=/myfilesystemif grep -qs $mount /proc/mounts; then  echo It's mounted.else  echo It's not mounted.  mount $mount  if [ $? -eq 0 ]; then   echo Mount success!  else   echo Something went wrong with the mount...  fifiFor more information on Exit and Exit Status, you can refer to the Advanced Bash-Scripting Guide.