title: The best way to check if a volume is mounted in a shell script in Mac OS?
body: <p>I had a shell script which I automated a copying process from my phone's folder to a local folder on my Mac and then deleted the originals on the phone. Previously I wrote </p>
  
  <pre><code>cd /Users/foo/Phone\ Backups/Phone\ One/Pictures
  echo "Meta info of the picture files in the local folder before backup"  &gt;&gt; /Users/foo/Documents/preBackup.txt
  find .  -exec stat -c " %n size %s bytes; LMT %y; CT %w; LAT %x; LSC %z; %F; Owned by: %U" {} \; | tee -a /Users/foo/Documents/preBackup.txt
  
  
  cp -a /Volumes/Foo\'s\ Phone\ One\ Pictures/. /Users/foo/Phone\ Backups/Phone\ One/Pictures
  echo "Backup complete. Delete all records on the phone."
  cd /Volumes/Foo\'s\ Phone\ One\ Pictures
  find . ! -type d -delete
  echo "Deleted."
  </code></pre>
  
  <p>Today when I ran my script I accidentally forgot to plug in my phone, and also afterward to my surprise all the picture files in my local folder got deleted as well. I guess it is because it didn't find my phone's picture folder so it was still in my local folder when it ran the command "find . ! -type d -delete".</p>
  
  <p>So now just wanna ask what's the best way to check if a volume is mounted in a shell script in Mac OS and if the name of the volume has ' and space?</p>
  
  <p>Thanks guys.</p>