How to handle spaces in script



I have the unmount() function below in my ~/.bashrc. It allows me
to unmount most file systems just by typing unmount. I now have a
USB drive mounted with a space in the file name like

/dev/sdf1 233G 152G 82G 66% /media/Passport WD-1

I've tried numerous ways to handle the space in the path name
"/media/Passport WD-1". How can this space or spaces be handled?



function unmount()
{

# Get sdXX or srXX drives, or CIFS mounted file systems. The -f3,4 will
# handle a path name with ONE space in it.
mntpoints="$(mount | egrep '192.168|\/dev\/sd|\/dev\/sr|cifs|loop' | cut -d ' ' -f3,4 | grep -v type)"

if [ "$mntpoints" ]; then
for i in $(echo "$mntpoints"); do

if [ "$i" != '/' ]; then
# if [ "$i" ]; then
echo Unmounting "$i"
sudo /bin/umount "$i"
fi

done
else
echo "No mounted file systems found."
fi

}
.


Quantcast