2014-10-09 257 views
3

我试图在adb shell上运行linux shell脚本。它给错误! 这里是整个故事:在adb shell上运行linux bash脚本

我写了一个简单的bash脚本hello.sh:

#!/bin/bash 
function hello 
{ 
    echo "hello world!" 
} 

hello 

运行它作为./hello.sh生产的O/P

hello world! 

现在我推送该文件到Android设备使用

adb push hello.sh /data/folder_name 

然后运行以下命令进入adb shell

adb shell 

亚行壳烧成以下命令

cd /data/folder_name 
chmod 755 hello.sh 
sh hello.sh 

这是我得到亚行外壳:

# sh hello.sh 
sh hello.sh 
function: not found 
hello world! 
hello: not found 
# 

这里发生了什么! 还是有一些不同的方式来编写功能的亚行外壳脚本

我搜索,但没有得到妥善解决 请帮助。

回答

4

不确定adb,但'函数'不是标准语法。这是在许多炮弹可用,但要定义一个函数的标准方法是:

hello() { echo hello world; } 
+0

完美!谢谢。:) – 2014-10-10 05:04:44

0

当为sh的时候,bash进入POSIX模式,并试图尽可能接近模仿sh历史版本的启动行为尽可能同时符合POSIX标准。

保留字function对于bash是可选的,但我认为对于历史版本sh是未知的。

尝试调用命令

bash /tmp/test.sh