Hello there
I'm using bash 2.05b (in mac OSX 10.3.4) and I've come across a weird behaviour that seems to get mentioned in other places on the 'net, but I've not been able to find out whether this has been addressed/cured?
Running the (still unpolished!) script below, the 'read' works fine, but then when it gets to the 'select' stage, it just jumps right to the end of the script. I tried using a 'read' statement instead of the 'select' - same behaviour.
Anyone know how to resolve this?
- yoxi
##########################
##########
###
#! /bin/bash
# this script parses 'diskutil list' to create 2 arrays:
# named available volumes (e.g. /volumes/Blah), and their disk IDs (e.g. disk0s10)
# it checks whether they're unmounted, then offers a list of
# unmounted volumes from which the user may choose to mount one
# - it only works for HDDs, not unmounted disk images etc.
getvols () {
linecount=0
while read dummy1 dummy2 voln dummy3 dummy4 diskn; do
# only keep lines which are mountable but unmounted volumes...
if [ -n "$voln" ] && [ "$voln" != "name" ] && [ -n "$diskn" ] && [ ! -d "/Volumes/$voln" ]; then
volnames[$linecount]=$voln
diskid[$linecount]=$diskn
linecount=$linecount+1
fi
done
echo "${volnames[*]}"
# will do a bit more error checking here once this works...
mountvol=""
PS3='Enter the number of the volume you want mounted: '
select mountvol in ${volnames[*]}; do
if [ $mountvol ]; then
diskutil mount /dev/"${diskid[($REPLY-1}]
}"
break
else
echo 'try again!'
fi
done
}
# here we go...
clear
echo 'This script will offer you a list of unmounted but available volumes'
echo 'from which you may choose to mount one, or'
echo 'type Ctrl-C to exit...'
echo ' '
diskutil list | getvols
Start Free Trial