3

For most ADB commands, I understand how to run them on a single line or even when placing them in a shell script, it can easily be done by implementing the secondary command after 'adb shell' but adding " ".

But for some reason nothing works on trying to run this command via a single line or even by putting it in a shell script:

adb shell 
task_id=$(dumpsys activity | grep -A2 "(dumpsys activity recents)"| grep '#'| cut -d ' ' -f 7| cut -c 2-); am task lock $task_id

Btw, this is to "screen pin" an application on Android devices.

2
  • 1
    does it give an error message, and what is the error message ? Commented Jun 26, 2017 at 21:57
  • 1
    In addition to any error messages, you should also mention whether you're running the adb command on Linux, Mac, or Windows. Commented Jun 26, 2017 at 22:18

1 Answer 1

2

You need quotes around your commands :

adb shell '
task_id=$(dumpsys activity | grep -A2 "(dumpsys activity recents)"| grep "#"| cut -d " " -f 7| cut -c 2-)
echo "locking task $task_id"
am task lock $task_id
'

or on one line:

adb shell 'task_id=$(dumpsys activity | grep -A2 "(dumpsys activity recents)"| grep "#"| cut -d " " -f 7| cut -c 2-); am task lock $task_id'
Sign up to request clarification or add additional context in comments.

2 Comments

omg... I thought I tried that. lol. I think I accidentally used double quotes instead. wow I'm dumb. lol. But thank you!
I just tried to activate skiagl with adb shell 'su;setprop debug.hwui.renderer skiagl;stop;start' , see doc here: developer.android.com/studio/run/… i never get the command line back

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.