First repair the syntax: Put things in quotes in the if statement.
EDIT: I thought you needed to refer to the var i
with $i
, but @tripleee showed me, that this is optional in bash arrays. I removed the extra $
characters.
nme=(Y6T1 Y6-T1 Y6.T1 Yr6T1 Yr6-T1 Yr6.T1 Yr6Term1)
DEVP=(/dev/disk2 /dev/disk3 /dev/disk4 /dev/disk5 /dev/disk6 /dev/disk7 /dev/disk8)
for ((i = 0; i < 7; i++)) ; do
if [ "${nme[i]} ${DEVP[i]}" = 0 ] ; then
echo "diskutil eraseDisk FAT32 ${nme[i]} ${DEVP[i]}"
else
echo “Formatted USBs” ; break
fi
done
If you want to check the vars being empty, introduce an error by looping until 8.
I have put an echo in front of the diskutil line, so you can test without doing something you do not want.
for ((i = 0; i < 8; i++)) ; do
if [ -z "${nme[i]}" ]; then
echo "loop $i: \${nme[i]} is empty";
break;
fi
if [ -z "${DEVP[i]}" ]; then
echo "loop $i: \${DEVP[i]} is empty";
break;
fi
echo "diskutil eraseDisk FAT32 ${nme[i]} ${DEVP[i]}"
done