I have a script that queries the device architecture from an android device, and uses that in a path to push a file to the device.

The code is similar to this:

ARCH=$(adb shell getprop ro.product.cpu.abi)
adb push libs/"$ARCH"/binary /data/local/tmp/binary

However, the path gets mangled. When piping the getprop command to a file, I can see that it returns a newline, which is probably the cause of the problem. I was under the impression that command substitution strips newlines, but either way, I tried:

 ARCH=$(adb shell getprop ro.product.cpu.abi | tr -d '\n')

with still no luck.

Any ideas/

  • 1
    It strips trailing newlines; "interior" newlines are preserved. – chepner Nov 20 '17 at 19:56
  • 1
    What is the output of the adb command, and what is the output of printf '%q\n' "$ARCH"? – chepner Nov 20 '17 at 19:57
  • @chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7a\r' – afuna Nov 20 '17 at 21:03
  • 1
    You don't have a newline; you have a carriage return, which the command substitution does not strip. – chepner Nov 20 '17 at 21:06
  • @chepner so using tr -d '\r' would be the way to go... – afuna Nov 20 '17 at 21:08

adb outputs a command with a DOS line ending. The command substitution strips the newline character, but not the carriage return; you'll have to strip that manually.

ARCH=$(adb shell getprop ro.product.cpu.abi)
adb push libs/"$ARCH"/binary /data/local/tmp/binary
  • I'm actually using an adb server on Windows, but running the script from Ubuntu (on Windows). I wonder if adb is conforming to Windows standards, but would return \n if it was running on linux. – afuna Nov 20 '17 at 21:14

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.