user2015001
user2015001

Reputation: 31

Script file to run in android devices with help of the sh present in adb shell

I am facing a problem in writing a shell script for android devices to be run only on sh present in the device (/system/bin/sh). I have written the following script

#!/system/bin/sh

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

If I run the shell by the below command it cant find the system/bin/sh root@xyz3g:/data # ./test_script.sh /system/bin/sh: ./test_script.sh: its giving No such file or directory

What could be the possible reasons for the above error.?

So if I am running this script by following command then I am getting a syntax Error .

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

I have confirmed the syntax but couldnt get any idea out of this.Can you please help me with this as I am an amateur in shell scripting.

  1. In addition to this , may I know if there is a difference(in regards of permissions and other applications) if I run this script in rooted samsung devices and google released phones like NEXUS 4,NEXUS 5

Thanks in advance.

Upvotes: 1

Views: 5379

Answers (3)

Pendge
Pendge

Reputation: 1

change the script_file dos2unix script_file

Upvotes: 0

Sonti Nagarjuna
Sonti Nagarjuna

Reputation: 61

Thanks Below steps worked for me

Step1: Open file in notepad++

Step2: Go To Edit-->EOL Conversion-->Unix/Osxformat

Step3: Save it

Upvotes: 5

straydog
straydog

Reputation: 11

in windows end of line is CR+LF
in android end of line is LF
I guess you edit the file in windows
change it to unix style may solve the problem

Upvotes: 1

Related Questions