Command substitution is adding a newline?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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/







share|improve this question
















  • 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 '%qn' "$ARCH"?
    – chepner
    Nov 20 '17 at 19:57











  • @chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7ar'
    – 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














up vote
0
down vote

favorite












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/







share|improve this question
















  • 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 '%qn' "$ARCH"?
    – chepner
    Nov 20 '17 at 19:57











  • @chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7ar'
    – 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












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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/







share|improve this question












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/









share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '17 at 19:38









afuna

1676




1676







  • 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 '%qn' "$ARCH"?
    – chepner
    Nov 20 '17 at 19:57











  • @chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7ar'
    – 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












  • 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 '%qn' "$ARCH"?
    – chepner
    Nov 20 '17 at 19:57











  • @chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7ar'
    – 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







1




1




It strips trailing newlines; "interior" newlines are preserved.
– chepner
Nov 20 '17 at 19:56




It strips trailing newlines; "interior" newlines are preserved.
– chepner
Nov 20 '17 at 19:56




1




1




What is the output of the adb command, and what is the output of printf '%qn' "$ARCH"?
– chepner
Nov 20 '17 at 19:57





What is the output of the adb command, and what is the output of printf '%qn' "$ARCH"?
– chepner
Nov 20 '17 at 19:57













@chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7ar'
– afuna
Nov 20 '17 at 21:03





@chepner: adb outputs armeabi-v7a, the printf outputs $'armeabi-v7ar'
– afuna
Nov 20 '17 at 21:03





1




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




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




@chepner so using tr -d 'r' would be the way to go...
– afuna
Nov 20 '17 at 21:08










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










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)
ARCH=$ARCH%$'r'
adb push libs/"$ARCH"/binary /data/local/tmp/binary





share|improve this answer




















  • 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







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405835%2fcommand-substitution-is-adding-a-newline%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










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)
ARCH=$ARCH%$'r'
adb push libs/"$ARCH"/binary /data/local/tmp/binary





share|improve this answer




















  • 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














up vote
2
down vote



accepted










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)
ARCH=$ARCH%$'r'
adb push libs/"$ARCH"/binary /data/local/tmp/binary





share|improve this answer




















  • 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












up vote
2
down vote



accepted







up vote
2
down vote



accepted






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)
ARCH=$ARCH%$'r'
adb push libs/"$ARCH"/binary /data/local/tmp/binary





share|improve this answer












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)
ARCH=$ARCH%$'r'
adb push libs/"$ARCH"/binary /data/local/tmp/binary






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '17 at 21:08









chepner

5,1551223




5,1551223











  • 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
















  • 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















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




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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405835%2fcommand-substitution-is-adding-a-newline%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

The Forum (Inglewood, California)

Palaiologos