下面的shell脚本在bash shell中工作得很好。但在android shell中产生错误。可能它必须对android使用的shell进行一些操作。但我该如何解决它?如果不是一个完美的解决方案,黑客也会为我做。Shell脚本在bash中工作,但不在'adb shell'上
壳脚本:
func()
{
local x
x=${1:3:1}
echo "x - $x"
if [ "${x}" = " " -o -z "${x}" ]; then
a="M"
else
a="S"
fi
echo "A - ${a} X - {x}"
}
func "abc=efg"
O/p在机器人外壳,
root:/ # sample.sh
x - =
/system/bin/sample.sh[14]: [: =: missing second argument
A - S X - {x}
上bash外壳O/P(Linux)的:
PC:~$ ./sample.sh
x - =
A - S X - {x}
脚本是否以'#!/ bin/bash'开头? – Barmar
@Barmar是的。它以bash shell上的#!/ bin/bash和Android shell上的#!/ system/bin/sh开头 –
Android上bash的版本是什么? – Barmar