When running a script that contains an array in a variable, the strings in the variable will be executed as a command, I don't need anything inside the array to be executed as a command, how to prevent that ?
I get the error sush: /su/su.d/1mount[5]: /mnt/runtime/default/MicroSD: can't execute: Is a directory
#!/system/bin/sh
count=0
LOG=/data/media/0/Logs/MicroSD.log
PARTITION="/dev/block/mmcblk1p3"
TARGET={"/storage/MicroSD" "/mnt/runtime/default/MicroSD" "/mnt/runtime/read/MicroSD" "/mnt/runtime/write/MicroSD" "/mnt/media_rw/MicroSD"}
FSTYPE=ext4
VOLDBLOCK=/dev/block/vold/179:66
[ $(wc -l $LOG) -gt 5000 ] && sed -i "1,$(($(wc -l $LOG|awk '{print $1}') - 5000)) d" $LOG
echo "$(date) Starting..." >> $LOG
for m in ${TARGET[@]}; do
mkdir $TARGET[$m] 1>> $LOG
done
contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0
else
return 1
fi
}
while ! ls $PARTITION
do
count=`expr $count + 1`
if test $count -ge 100
then
break
else
sleep 0.1
fi
done
mount_partition(){
ls -d $TARGET[$i] 1>>$LOG 2>>$LOG
if ! ls $PARTITION
then
echo "$PARTITION not found" 1>>$LOG 2>>$LOG
else
while ! ls -d $TARGET[$i]
do
count=`expr $count + 1`
if test $count -ge 100
then
break
else
sleep 0.1
fi
done
sleep 0.5
if ! mountpoint -q $TARGET[$i]
then
mountres=`mount -t $FSTYPE -o rw $PARTITION $TARGET[$i] 2>&1 > /dev/null`
mountret=$?
while test $mountret -ne 0
do
if contains "$mountres" "nvalid argument"
then
echo "\n******************************************\n2nd partition filesystem is invalid\n******************************************\n" 1>>$LOG 2>>$LOG
break
else
count=`expr $count + 1`
if test $count -ge 300
then
break
else
if mount -t $FSTYPE -o rw $VOLDBLOCK $TARGET[$i]
then
break
else
sleep 0.1
fi
fi
fi
mountres=`mount -t $FSTYPE -o rw $PARTITION $TARGET[$i] 2>&1 > /dev/null`
mountret=$?
done
mount -t $FSTYPE -o rw $PARTITION $TARGET[$i] 1>>$LOG 2>>$LOG
mount -t $FSTYPE -o rw $VOLDBLOCK $TARGET[$i] 1>>$LOG 2>>$LOG
else
echo "2nd partition already mounted at $TARGET[$i] ..." 1>>$LOG 2>>$LOG
fi
fi
}
for i in ${TARGET[@]}; do
mount_partition &
done
echo "\n******************************************\nMount output\n******************************************" >> $LOG
mount >> $LOG
chown 1023:1023 $LOG
chmod 770 $LOG
sh
doesn't really have "proper" arrays, as I recall. The man page suggests that expressions wrapped in{}
will be executed (it refers to these as one type of "compound command"), so that seems to be what it's doing when you try to defineTARGET={ "some" "values" }