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 hello.sh:
#!/bin/bash
function hello
{
echo "hello world!"
}
hello
runs it like. /hello.sh, issues the o / p command
hello world!
Now I have pushed the file to my android device with
adb push hello.sh /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 hello.sh
sh hello.sh
This is what I get on adb shell:
# sh hello.sh
sh hello.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
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/test.sh
source to share