Search code examples
bashshellinputadb

How to simulate user input when writing bash script on a shell device


I am writing a script to automate a large number of steps needed for provisioning an android device. However, I am having a trouble with one particular step. There is a command that I have to run on an android device via adb shell "...command...". The problem is that this command then requires an input from the keyboard, which is always "1".

I tried this with the xdotool, like this: adb shell "...command"..." ; xdotool 1*. However, this does not work because the second command will execute only after the first one is finished, but the first one cannot be finished without an input. Also, I think this still wouldn't work because xdtool 1 would input 1 in the current terminal, and not in the adb shell one. And I can't use adb shell "xdotool 1", because the android device does not have xdotool. I read about expect scripts as well, but was unable to implement them in this situation. Does anyone know how to solve this?


Solution

  • As stated in the comments, this works:

    adb shell "...command..." <<< "1"