• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

Making a simple ADB shell script.

Search This thread

ComputerTech312

Senior Member
Jul 9, 2021
93
37
So i am trying to make a simple shell script which will execute multiple ADB commands, here's what i have come up with.

#bin/sh echo ------------------------------- echo Removing lockscreen ads... echo ------------------------------- adb shell pm disable-user --user 0 com.amazon.kindle.kso

when i try to do, bash file.sh it just says bash is a unknown command, so what am i doing wrong? :(
 

jwoegerbauer

Senior Member
Jul 11, 2009
6,797
19
1,588
European Union
ADB is a commandline tool to be run either on Windows OS, preferredly wrapped into a Windows CMD script, or in Android OS, preferredly wrapped into an Android shell script.

If you intend to run ADB commands in Android's terminal then a shell script would look like this
Code:
#!sbin/sh
ADB=/usr/bin/adb
"$ADB" shell "<COMMAND-HERE>"
 
Last edited:

ComputerTech312

Senior Member
Jul 9, 2021
93
37
ADB is a commandline tool to be run either on Windows OS, preferredly wrapped into a Windows CMD script, or in Android OS, preferredly wrapped into an Android shell script.

If you intend to run ADB commands in Android's terminal then a shell script would look like this
Code:
#!sbin/sh
ADB=/usr/bin/adb
"$ADB" shell "<COMMAND-HERE>"
Okay, thank you. will try that right away :D

i could also use this in a windows batch file?(sorry bit of a noob about this :p)
 

SMcC2

Senior Member
Feb 22, 2014
282
138
Texas
OnePlus 6T
It really depends on what you're trying to do.
I wrote the following as a simple .bat file and ran it from my platform-tools directory on my Windows laptop:

@Echo Off
echo Checking for Devices.
adb devices
echo Is device present?
echo (Press Enter if yes, Ctrl+C or close Script if not)
pause
echo Rebooting to recovery.
adb reboot recovery
echo Waiting 30 seconds for reboot.
timeout /t 30
echo Checking for Devices.
adb devices
echo Is device present?
echo (Press Enter if yes, Ctrl+C or close Script if not)
pause
echo Decrypting Data in TWRP.
adb shell twrp decrypt ******
pause

And it does the following:

MyBatFile.PNG
 

jwoegerbauer

Senior Member
Jul 11, 2009
6,797
19
1,588
European Union
What would the changes be to your code if it's a Windows CMD script? would changes to the path be required and such?
An Android shell script and a Windows bash script ( including a Powerpoint script ) are in all aspects different with regards to coding, this because Android shell scripts are coded using Linux synthax.

BTW:

To not have to dance on 2 weddings I create my scripts mainly as pure Android shell scripts, which I copy from PC to Android device, and then start executing it from PC by means of ADB using a Windows bash script.

Example Windows bash script:

Code:
@echo off
adb devices
adb push <ANDROID-SCRIPT-PATH-ON-PC-HERE> /tmp
adb shell "chmod 0755 /tmp/<ANDROID-SCRIPT-NAME-HERE>"
adb shell "cd /tmp; $(<ANDROID-SCRIPT-NAME-HERE>);"
adb shell "rm -f /tmp/<ANDROID-SCRIPT-NAME-HERE>"
 
Last edited:
  • Like
Reactions: xXx yYy

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    What would the changes be to your code if it's a Windows CMD script? would changes to the path be required and such?
    An Android shell script and a Windows bash script ( including a Powerpoint script ) are in all aspects different with regards to coding, this because Android shell scripts are coded using Linux synthax.

    BTW:

    To not have to dance on 2 weddings I create my scripts mainly as pure Android shell scripts, which I copy from PC to Android device, and then start executing it from PC by means of ADB using a Windows bash script.

    Example Windows bash script:

    Code:
    @echo off
    adb devices
    adb push <ANDROID-SCRIPT-PATH-ON-PC-HERE> /tmp
    adb shell "chmod 0755 /tmp/<ANDROID-SCRIPT-NAME-HERE>"
    adb shell "cd /tmp; $(<ANDROID-SCRIPT-NAME-HERE>);"
    adb shell "rm -f /tmp/<ANDROID-SCRIPT-NAME-HERE>"