I made some aliases to quickly reverse tether.

alias t='r && sh && n'
alias n='netcfg rndis0 dhcp'
alias sh='ad shell'
alias r='ad kill-server && ad start-server'
alias ad='adb'

I want to enter t (which turns on reverse tethering) but the aliased command doesnt do anything past sh

How to automate this better?

(I guess its because its not in first shell anymore but android adb shell)

UPDATE: I edited the .bashrc as answered by Stephen Schrauger but the command enters me into adb shell and when i disconnect usb cable I get netcfg: command not found

The aliases are now:

alias t='r && sz $n'
n='netcfg rndis0 dhcp'
alias sz='ad shell'
alias r='ad kill-server && ad start-server'
alias ad='adb'

What is wrong now?

UPDATE2 moved here:Help with this ADB REVERSE Tethering Script?

  • Made update 2 added autoturning on tethering (no more need for paid apps constantly bloating device) and wrote current issues
    – user42276
    Mar 21, 2014 at 17:10

1 Answer 1


This is more of a linux question, and it may need to be moved to superuser.se, but I can answer it.

On linux, you string commands using && (or || or just ;). With &&, the first command must finish executing and have no error codes in order for the next command in the sequence to run.

In your setup, it looks like you want to open an ADB shell, and then run netcfg rndis0 dhcp on the adb shell. However, Linux doesn't do that. Instead, it is waiting for the ADB shell to exit without errors, after which time it will run netcfg rndis0 dhcp on the desktop computer's shell.

If you want to run a command on the Android device, you don't start an interactive ADB shell (the default); rather, you pass the command like so:

adb shellnetcfg rndis0 dhcp

You'll need to change your alias for n to be a variable instead. Remove the alias directive so the line just reads n='netcfg rndis0 dhcp'. Then change your alias for t to be as follows

alias t='r && sh $n'

  • And, by the way, you probably shouldn't use sh as an alias, since most linux systems already have a command for sh. Mar 17, 2014 at 18:53
  • Thank you for your answer.Please tell me why i still get a failure
    – user42276
    Mar 17, 2014 at 19:38
  • You need to reload your aliases after you edit your .bashrc file. The easiest way to do this is simply to reboot your desktop. It sounds like your old aliases are still hanging around in memory. Mar 17, 2014 at 19:40
  • thanks it works! :D (I exited the terminal and launched it again as I always did to reload .bashrc changes but it didn't work and after relogging in it works :D) where did you learn that $n ? (I want to learn more about Linux) Btw can you help me with the apps not recognizing internet question please?
    – user42276
    Mar 17, 2014 at 19:45
  • 1
    I think the updates you made would be better made into a brand new question. It's preferred to have a single question per stackexchange question, rather than multiple ones. If you start a new question, you can link to this one so people can understand a bit more of the background. Mar 21, 2014 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .