Mount .sparseimage from .bash_profile
I need to mount a .sparseimage from .bash_profile but I don't get how to do it. I tried:
alias of22='hdiutil attach "Documents/OF.sparseimage" -mountpoint "$HOME/OpenFOAM" > /dev/null ; . $HOME/OpenFOAM/OpenFOAM-2.2.0/etc/bashrc'
but this gives me:
hdiutil: attach failed - no mountable filesystem
if I double-click on it or I put it in Startup Items it works (but i need also to source the bashrc after the mount)
What's the problem?
Solution 1:
The open(1)
command can do it:
/usr/bin/open /full/path/to/OF.sparseimage
Solution 2:
In fact, the command you use will mount the disk image, but there are two problems I see.
Before I get into those I want to clarify to all readers (as I had this problem), the following command will mount a disk image:
hdiutil attach image_name.sparseimage -mountpoint mount_point
where you specify image_name.sparseimage
and mount_point
to your liking.
Here are the problems with your specific case that I see:
1) You are not mounting it in the bash_profile. You are creating an alias. You must run the alias first to mount the disk image (with of22
in your case).
2) Seems like you've done #1 because you get the error message "no mountable filesystem". This is probably because the disk image is using a relative path, which means you must run of22
from the parent directory (which seems to be your home directory in this case).
Try changing the command to
hdiutil attach "$HOME/Documents/OF.sparseimage" -mountpoint "$HOME/OpenFOAM"
Notice the addition of "$HOME".