0

So I can issue a shell command on my GalaxyS5 device using this:

$ adb shell run-as com.steenriver.littlecrane 'sh -c pwd'
/data/data/com.steenriver.littlecrane
$ adb shell run-as com.steenriver.littlecrane 'sh -c ls'
cache
files
lib

So far so good.

Now, if I want to supply an argument to the command, the shell will not see it:

$ adb shell run-as com.steenriver.littlecrane 'sh -c ls files'
cache
files
lib

I also tried starting a shell outright, and then type in commands in the terminal, but doing that just makes adb hang completely, and output nothing.

$ adb shell run-as com.steenriver.littlecrane 
u0_a197@kwifi:/data/data/com.steenriver.littlecrane $ ls
<hangs>

How can I give an adb shell command with arguments?

  • I'll leave this for someone more qualified, but I think this isn't a question for an end user. Maybe on SO. – HasH_BrowN Sep 26 '15 at 1:10
1

"-c" switch of sh command requires (and uses) a single argument which is the full shell command as a string.

This should do the trick:

adb shell run-as com.steenriver.littlecrane 'sh -c "ls files"'

In the original example, "files" is interpreted as an extra argument of the "sh" command (simply discarded when using the "-c" switch) , not of the "ls" command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.