1

I am trying to pass the output of a linux command to another command as an argument in Android debugging.

Here is the steps I want to combine .

  1. Finding out the binary path using adb shell pm path com.test.example

    The output being : package:/data/app/test.apk

  2. Strip first 9 characters from the output using cut -c 9-

    The output being /data/app/test.apk

  3. Use the output of 2nd in my 3rd command adb pull

I tried doing something like :

adb shell pm path com.test.example | cut -c 9- | adb pull -

But this doesn't work. Can someone suggest why and what would be the correct solution or a better approach?

Community
  • 1
  • 1

2 Answers2

2

You can pass output of one command to another command as arguments by using xargs.

echo "Name" | echo             #next line as output
echo "Name" | xargs echo       # this will output Name

So you can do it by following expression :-

adb shell pm path com.test.example | xargs cut -c 9- | xargs adb pull -

For more information you can follow this link.

Devavrata
  • 1,785
  • 17
  • 30
1

I think you need to distinguish between standard input and parameters. Not every command understands - as referring to standard input, and even those that do usually treat it differently from parameters.

What you probably want is this:

adb pull "$(adb shell pm path com.test.example | cut -c 9-)"
l0b0
  • 55,365
  • 30
  • 138
  • 223