Run linux bash script on adb shell

I am trying to run a linux shell script in adb shell. It gives errors! Here's the whole story:

I wrote a simple bash script

function hello
    echo "hello world!"



runs it like. /, issues the o / p command

hello world!


Now I have pushed the file to my android device with

adb push /data/folder_name


then ran the following command to enter in adb shell

adb shell


The following commands run in adb shell

cd /data/folder_name
chmod 755


This is what I get on adb shell:

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


What's going on here! Or is there another way to write a function for adb shell script

I searched but didn't get the right solution Please help.


source to share

2 answers

Not sure about adb, but "function" is not standard syntax. It is available in many shells, but the standard way to define a function is:

hello() { echo hello world; }




When called sh

, bash goes into posix mode, and it tries to mimic the startup behavior of historical versions of sh as closely as possible, while still conforming to the POSIX standard.

The reserved word function

is optional for bash, but unknown to historical versions I guess sh


Try calling the command like

bash /tmp/




All Articles