shellは端末上でコマンドを実行するサブコマンドである。コマンドを1回だけ実行するワンショット実行と、プロンプトが起動する対話シェルの2つの使い方がある。

コマンドを1回だけ実行する

shellの後ろにコマンドを指定すると、そのコマンドを端末上で実行して結果を返す。

$ adb shell echo hello
hello

コマンドを省略すると対話シェルが起動する

コマンドを指定せずにshellを実行すると、端末のプロンプトが起動する対話シェルになる。

$ adb shell
SH-02M:/ $ echo interactive-test
interactive-test
SH-02M:/ $ exit

exitで対話シェルを終了し、ホスト側のシェルに戻る。

-t/-Tでpty割り当てを制御する

対話シェルではホスト側がターミナルに接続されていれば端末(pty)が自動的に割り当てられるが、ワンショット実行ではホスト側の状態に関わらずデフォルトでptyが割り当てられない。

$ adb shell tty
not a tty

-Tを付けると、ptyの割り当てを明示的に無効化できる。

$ adb shell -T tty
not a tty

-tを1つ付けただけでは、ホスト側がターミナルに接続されていない環境では効果がない。

$ adb shell -t tty
Remote PTY will not be allocated because stdin is not a terminal.
Use multiple -t options to force remote PTY allocation.
not a tty

-tを2つ重ねて-ttにすると、ホスト側の状態に関係なくptyの割り当てを強制できる。

$ adb shell -tt tty
/dev/pts/0