How to run BASH script in my Android?

守給你的承諾、 提交于 2019-12-02 17:37:42

May be it will work when calling interpreter with a script?

$ bash ./test.sh

I saw, that although it is specified #!/bin/bash error was posted by sh - may be it do wrong.

UPD

$ sh ./test.sh

in Android the shell is located in /system/bin/sh not /bin/sh like it is on most Unix-like systems. So even if you change #!/bin/bash to #!/bin/sh it will still not work. you'll have to use #!/system/bin/sh

Android is not a GNU/Linux distribution so you can't expect that all scripts that run on GNU/Linux to also work on Android.

Most Android devices don't have a bash interpreter installed. If you really need to run the script across Linux and Android, you could try using BusyBox but that will require rooting your device (and potentially voiding your warranty). Even then though, I don't know if the ifconfig utility is included in BusyBox.

I would strongly recommend using the Android SDK to write an app to do whatever your trying to accomplish.

As was stated, the Android OS (up to and including 4.0) does not include the BASH interpreter (just shell). While BusyBox is a great tool, I believe it's only a single executable that combines stripped-down-functionality-for-size versions of common UNIX utilities, but doesn't actually include the BASH interpreter.

For an Android compiled version of the BASH interpreter, refer to this Forum thread: http://forum.xda-developers.com/showthread.php?t=537827

Kenpachi

You can install Busybox, which provides you with many utilities such as awk, file, etc... and Terminal Emulator.

  1. Create a shell file with #!/system/bin/sh as the first line (shebang)
  2. Now place the completed script under /system/xbin or /system/bin and run it from the Terminal Emulator

The information is an excerpt from this article : HOW TO RUN SHELL SCRIPTS ON ANDROID DEVICES

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!