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.
adbcommand on Linux, Mac, or Windows.