QUESTION :
Plan: I want to unmount an iscsi volume on my OS X Desktop in a script only if it’s mounted. So far, I’ve identified the disk as disk4s2
with:
diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev...
Continuing the line in order to unmount:
diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev | diskutil unmount [disk4s2]
but how do I refer to the disk in square brakets? I realize this may not be the
most efficent solution. Any help would be appreciated.
ANSWER :
xargs is the command you need. It takes stdin and converts it to arguments to pass to a command.
Assuming that diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev
gives you the disk name, do:
diskutil list | grep 'V-Movies' | rev | cut -c1-7 | rev | xargs diskutil unmount