Monday, September 26, 2011

Android sh script, why failed with [ not found

A simple sh script, but run failure with error: [ not found.
#!/system/bin/sh
if [ $? eq 0 ]; then
    echo "Command run successful"
fi
The same script can run well on Linux.
I dont know why, but I finally got a solution.
Upload a busybox, change it to executable permissions, create a soft link "[" to busybox. Like the following:
-rwxr-xr-x 500      500       1877260 2011-09-22 02:42 busybox
lrwxrwxrwx root     root              2011-09-26 08:15 [ -> /sbin/busybox
Run the sh script again, which shall give no error any more.
Finally, make sure the searching path $PATH can find command "busybox", and "[".