Command substitution is adding a newline?

Clash 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/
bash shell-script variable newlines
 |Â
show 1 more comment
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/
bash shell-script variable newlines
1
It strips trailing newlines; "interior" newlines are preserved.
â chepner
Nov 20 '17 at 19:56
1
What is the output of theadbcommand, and what is the output ofprintf '%qn' "$ARCH"?
â chepner
Nov 20 '17 at 19:57
@chepner: adb outputsarmeabi-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 usingtr -d 'r'would be the way to go...
â afuna
Nov 20 '17 at 21:08
 |Â
show 1 more comment
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/
bash shell-script variable newlines
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/
bash shell-script variable newlines
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 theadbcommand, and what is the output ofprintf '%qn' "$ARCH"?
â chepner
Nov 20 '17 at 19:57
@chepner: adb outputsarmeabi-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 usingtr -d 'r'would be the way to go...
â afuna
Nov 20 '17 at 21:08
 |Â
show 1 more comment
1
It strips trailing newlines; "interior" newlines are preserved.
â chepner
Nov 20 '17 at 19:56
1
What is the output of theadbcommand, and what is the output ofprintf '%qn' "$ARCH"?
â chepner
Nov 20 '17 at 19:57
@chepner: adb outputsarmeabi-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 usingtr -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
 |Â
show 1 more comment
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
I'm actually using anadbserver on Windows, but running the script from Ubuntu (on Windows). I wonder ifadbis conforming to Windows standards, but would returnnif it was running on linux.
â afuna
Nov 20 '17 at 21:14
add a comment |Â
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
I'm actually using anadbserver on Windows, but running the script from Ubuntu (on Windows). I wonder ifadbis conforming to Windows standards, but would returnnif it was running on linux.
â afuna
Nov 20 '17 at 21:14
add a comment |Â
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
I'm actually using anadbserver on Windows, but running the script from Ubuntu (on Windows). I wonder ifadbis conforming to Windows standards, but would returnnif it was running on linux.
â afuna
Nov 20 '17 at 21:14
add a comment |Â
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
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
answered Nov 20 '17 at 21:08
chepner
5,1551223
5,1551223
I'm actually using anadbserver on Windows, but running the script from Ubuntu (on Windows). I wonder ifadbis conforming to Windows standards, but would returnnif it was running on linux.
â afuna
Nov 20 '17 at 21:14
add a comment |Â
I'm actually using anadbserver on Windows, but running the script from Ubuntu (on Windows). I wonder ifadbis conforming to Windows standards, but would returnnif 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
It strips trailing newlines; "interior" newlines are preserved.
â chepner
Nov 20 '17 at 19:56
1
What is the output of the
adbcommand, and what is the output ofprintf '%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