【问题标题】:Script file to run in android devices with help of the sh present in adb shell借助 adb shell 中的 sh 在 android 设备中运行的脚本文件
【发布时间】:2014-05-09 13:22:13
【问题描述】:

我在为 android 设备编写 shell 脚本时遇到问题,该脚本只能在设备中存在的 sh (/system/bin/sh) 上运行。 我写了以下脚本

#!/system/bin/sh

while [ 1 ]; do
   cat /sys/kernel/debug/gpio > /dev/kmsg
   sleep 2
done

如果我通过以下命令运行 shell,它将找不到 system/bin/sh root@xyz3g:/data # ./test_script.sh /system/bin/sh: ./test_script.sh:它给没有这样的文件或目录

出现上述错误的可能原因是什么?

因此,如果我通过以下命令运行此脚本,则会收到语法错误。

test_script.sh[2]: syntax error: 'while' unmatched

我已经确认了语法,但无法从中得到任何想法。由于我是 shell 脚本的业余爱好者,请你帮我解决这个问题。

    提前致谢。

【问题讨论】:

  • 您的脚本文件是否标记为可执行文件?

标签: android linux bash shell


【解决方案1】:

感谢以下步骤对我有用

Step1:在记事本++中打开文件

Step2: 编辑-->EOL 转换-->Unix/Osxformat

第三步:保存

【讨论】:

  • 感谢您的快速简单提示,希望我能给您更多积分。
【解决方案2】:

在windows中,行尾是CR+LF
在 android 行尾是 LF
我猜你在 Windows 中编辑文件
改成unix风格可能会解决问题

【讨论】:

    猜你喜欢
    • 2018-08-10
    • 2020-03-16
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    相关资源
    最近更新 更多