android - 在 adb shell 上运行 linux bash 脚本

标签 android linux shell adb

<分区>

我正在尝试在 adb shell 上运行 linux shell 脚本。它给出了错误! 这是整个故事:

我写了一个简单的 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

在 adb shell 中触发以下命令

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

这是我在 adb shell 上得到的:

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

这里发生了什么! 或者是否有一些不同的方法来为 adb shell 脚本编写函数

我搜索过但没有找到合适的解决方案 请帮忙。

最佳答案

不确定 adb,但“函数”不是标准语法。它在许多 shell 中都可用,但定义函数的标准方法是:

hello() { echo hello world; }

关于android - 在 adb shell 上运行 linux bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26278680/

相关文章:

java - 如何在Activity中使用回调

android - 我需要从原始文件夹动态添加通知声音 - Android

linux - 使用命令行以非交互方式对文件进行拼写检查

shell脚本中的Mysql Dump,自动从settings.php读取DB变量

java 文件是从命令行执行的,而不是从浏览器(apache)执行的?

linux - SSH 并创建一个名为机器名称的日志文件

java.lang.InstantiationException : can't instantiate class; no empty constructor 异常

java - 在android中绘制路径?

java - Launch4j maven 插件不能在 64 位 linux 机器上运行

linux - 组用户名将 root 显示为组但不允许删除