title: How do I run "adb shell" commands in a terminal emulator locally on an Android device?
body: <p>From a shell on my PC, I can run <code>adb shell cmd package list packages</code>, and get a list of all installed packages. I would like to run this and similar commands locally on my Android phone (Nexus 6P) in a terminal emulator (currently using Termux). </p>
  
  <p>If I open the same shell with <code>/system/bin/sh</code>, and then try to run <code>/system/bin/cmd package list packages</code>, nothing happens (no errors, just outputs nothing and reloads the prompt). </p>
  
  <p>If I run <code>/system/bin/cmd -l</code> the list of options appears as expected. <code>$PATH</code> and <code>$LD_LIBRARY_PATH</code> are the same in both environments. One major difference is that <code>echo $USER</code> returns "shell" from <code>adb shell</code>, but returns my local username from <code>/system/bin/sh</code> launched from Termux.</p>
  
  <p>Is there any way to replicate the behavior of commands run from <code>adb shell</code> in a terminal emulator locally on Android?</p>
  
  <p>Edit:
  My device is rooted, and I am OK with root only solutions.</p>