shell script in android gives [: not found

2019-02-25 08:09发布

I have this script which works on my linux machine

#!/bin/sh
c=1
if [ $c == 1 ]
then
  echo c is 1
else
  echo c is 0
fi

But when I use this in android as follows:

#!/system/bin/sh
c=1
if [ $c == 1 ]
then
  echo c is 1
else
  echo c is 0
fi

It gives an error like:

[: not found

EDIT

Is there any other logic to check the value of $c, whether it is 1 or 0 ?

Android shell have problem with [] in if so is there any other way to check the value of c ?

8条回答
Animai°情兽
2楼-- · 2019-02-25 08:31

How about checking that the .sh file doesn't contain a carriage return before line feed.

Windows \r\n -> CR LF

Unix \n -> LF

查看更多
Bombasti
3楼-- · 2019-02-25 08:37

andriod shell sh is actually a link to busybox, and it is invoked as

busybox sh

you need setup [ applets manually

busybox ln -s /your_original_sh_path/busybox [ 

if you don't know where busybox is put, try list the /system/bin/sh which you give

ls /system/bin/sh
busybox which busybox
查看更多
登录 后发表回答