Have aliases in adb shell non-interactive mode

5.7k Views Asked by At

Hi I need to run things in the form of adb shell <command>

When I test everything out inside adb shell, it works because I was able to set some aliases in .bashrc. However, when I do adb shell <command>, nothing works because .bashrc is not used when you run adb shell <command>, because it's in the non-interactive mode.

How can I work around this? Can I adb push some files to the filesystem so that the alias will be there when adb shell is run?

3

There are 3 best solutions below

0
On

One way to do this is to issue several shell commands in a single ADB command. You can put them in a string, and separate them with semicolons, thus:

adb shell "alias foo bar ; export MY_VARIABLE=/path/to/somewhere ; my_executable "

The " are crucial here, make sure they are paired up correctly. You could run your .bashrc this way, thus:

adb shell "source /path/to/.bashrc ; my_executable"

1
On

You can write a bash script that sets the aliases and then executes your shell:

#!/usr/bin/bash
. $HOME/.bashrc
adb shell $@
6
On

If your android device is rooted you can add your aliases for adb shell into the /system/etc/mkshrc file.