2

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?

user42276
  • 547
  • 1
  • 4
  • 15
  • Made update 2 added autoturning on tethering (no more need for paid apps constantly bloating device) and wrote current issues – user42276 Mar 21 '14 at 17:10

1 Answers1

2

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'

Stephen S
  • 5,407
  • 6
  • 45
  • 59
  • And, by the way, you probably shouldn't use sh as an alias, since most linux systems already have a command for sh. – Stephen S Mar 17 '14 at 18:53
  • Thank you for your answer.Please tell me why i still get a failure – user42276 Mar 17 '14 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. – Stephen S Mar 17 '14 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 '14 at 19:45
  • I'd like to upvote you but I need 15 reputation – user42276 Mar 17 '14 at 19:48
  • The $ is just the way bash references variables that have been set. So you set a var like myvar=123 and reference it with $myvar (ex echo $myvar). As for learning more about linux, I suggest looking at this question at the superuser stackexchange site. That site is dedicated to linux questions. https://superuser.com/questions/36605/learning-the-basics-of-linux-unix – Stephen S Mar 18 '14 at 13:43
  • I just improved my command but I have a few more inquiries.Please help.Also I just upvoted you because Ive enough reputation – user42276 Mar 21 '14 at 17:01
  • 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. – Stephen S Mar 21 '14 at 17:12
  • ok Ive done as you wrote – user42276 Mar 21 '14 at 17:20