mymount () {
local args=( "$@" )
local dir="${args[-1]}"
test -d "$dir" || mkdir -p "$dir" || exit 1
command mount "$@"
}
On most Unices, with most file systems, the mount
utility requires that the mountpoint be an existing directory.
With the bash
shell function above, this directory is created if it does not already exist. The mountpoint is assumed to be the last argument on the command line when invoking the function. This allows you to mount a device anywhere without manually creating the mountpoint.
This is probably somewhat like whatever it is that creates the /media/username
mountpoint on your system does.
Likewise, you could define myumount
that unmounted a device and removed its mountpoint.
This obviously does not get around the fact that the directory can't be created by mount
(or deleted by umount
), at least not by the mount
implementations that I know about, but it allows you to hide the creation of the directory in a function.
Unix philosophy: Do one thing and do it well.
mount
requires a directory to mount something at. Creating this directory is the task for mkdir
.