shell script in android gives [: not found

前端 未结 8 1322
一个人的身影
一个人的身影 2021-01-20 23:31

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

相关标签:
8条回答
  • 2021-01-21 00:22

    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
    
    0 讨论(0)
  • 2021-01-21 00:24

    use /system/bin/cmp for equality test. if you need numerically test, substitute $(($c == 1)) with $c

    #!/system/bin/sh
    echo $c >/tmp/a
    echo 1 >/tmp/b
    if cmp /tmp/a /tmp/b
        echo c is 1
    else
        echo c is 0
    fi
    
    0 讨论(0)
提交回复
热议问题