Have the script create a two line script of its own, and run that.
Please post that syntax when you get a chance.
Here's my latest rev with additional window dressing. The assembling of the command itself remains identical... and it's still the 'geek' version (i.e., sans sanity checks and/or any guided tours):
#!/bin/bash -
# psd ::: Partition Service Disk
# flexible script to facilitate disk partitioning
#(c)EF/-HI-2011.Jun.07 [rev:2011.Jun.11]
IFS=$' \t\n'
declare -x PATH=/bin:/sbin:/usr/bin:/usr/sbin
declare -i x=0 pNum=0 dNum=666 # <--Initialize to an improbable disk number.
declare -i tSize=20 # <--Preallocate 20 gigs for the 'remainder' partition.
### OBS/NB: all sizes in gigabytes. ###
PRG=`basename "$0"`
# Variable data values may be edited and/or commented out entirely...
# >========================================>
name1='"Service Lion"' size1=17
name2='"Service Snow"' size2=15
name3='"Service Leopard"' size3=23
name4='"Service Tiger"' size4=12
name5='"Mac OS 10.3.4"' size5=1
name6='"Mac OS 10.3.4 Disc 2"' size6=1
name7='"Mac OS 10.4.6"' size7=4
name8='"Mac OS 10.4.7"' size8=6
name9='"Mac OS 10.5.6"' size9=8
name10='"Mac OS 10.6.3"' size10=9
name11='"Mac OS 10.7.0"' size11=9
name12='"Service Data"' size12=R
# <========================================<
# ...but, exactly one active partition should be assigned a size of R.
#-----------------------------------------------------------------------------#
Message () { printf '%s: %s: %s\n' "$PRG" "$1" "${2:-}" >&2; }
Bailout () { ((x+=1)); Message 'bailing on error' "${*:-}"; exit $x; }
NoError () { ((x+=$1)); [ $1 -eq 0 ] || Message error "${2:-}"; return $1; }
trap -- 'stty echo -igncr; [ $x -eq 0 ] && echo "$PRG: no errors :-)"' EXIT
trap -- 'printf "\e[0;39m\n"; ((x+=1)); exit $x' INT QUIT ABRT TERM
#-----------------------------------------------------------------------------#
# Count and list active partitions (number, name and size):
for i in {1..12}
do
j=name$i k=size$i
if [[ -n ${!j} ]]
then
((pNum+=1))
[ ${!k} = R ] && z=$tSize || z=${!k}
printf '%2d: %-32s %7dG' $pNum "${!j}" "$z"
[ ${!k} = R ] && echo ' (min)' || echo
fi
done
NoError $? 'had a problem listing partitions.' || Bailout 'whatzup with that?'
echo
printf '%2d partitions planned; ' $pNum
# Calculate total size:
for s in ${!size*}; do ((tSize+=$s)); done # note: Bash math ignores the R.
NoError $? 'had a problem calculating total size of all partitions,'
printf 'total space needed %dG.\n\n' $tSize
read -e -s -p '[type any character to continue] ' -n 1 foo
printf '\r\e[2K\e[0;39m\n'
df -h -l
echo
sleep 1
while [ $dNum -eq 666 ] || [ $dNum -eq 0 ] # Disallow boot volume selection.
do
read -e -p 'enter the INTEGER of the /dev/disk_ to partition: ' dNum
done
NoError $? 'integer input' || Bailout 'odd read loop activity. (e.g., PEBKAC)'
echo
c=
for i in {1..12}
do
j=name$i k=size$i
if [[ -n ${!j} ]]
then
[ ${!k} = R ] && g= || g=G
c="$c JHFS+ ${!j} ${!k}$g"
fi
done
NoError $? 'had a problem while assembling the command.' ||
Bailout 'best not to proceed, since the command might be flawed.'
Message 'script is now ready to execute the following command'
echo
echo diskutil partitionDisk /dev/disk$dNum $pNum APM $c
NoError $? 'had a problem echoing the assembled command.' ||
Bailout 'best not to proceed, since the command might be flawed.'
echo
goAhead=n
read -e -p "permit $PRG to ERASE /dev/disk$dNum ? (y/n [n]): " goAhead
echo
if [[ $goAhead != y ]]
then
Bailout 'task aborted by user.'
else
trap '' HUP INT QUIT ABRT TERM # Prevent interruptions.
eval diskutil partitionDisk /dev/disk$dNum $pNum APM $c
NoError $? 'um... diskutil had some kinda problem. :-('
fi
exit $x
-HI-
Edit: if it wasn't already apparent, then let's just establish the fact that —when using this script —trying to create a volume with hard (') or soft (") quotes
in its name is a recipe for fail.