Problem with passing path containing spaces and brackets
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I use Thunar file explorer and pass pathname and filename to a script audioplay. audioplay runs play command on my android via ssh which plays a song.
audioplay script :: cat audioplay
if [ $# -eq 1 ] ; then
echo " Playing..." "$@"
sshpass -p $passwd ssh root@192.168.43.10 -p $port play "$@"
else
echo " No Input audio file."
fi
play script on my android :: cat play
#!/data/bin/bash
# Avoid linker errors due to libOpenSLES.so:
echo "File ::" "$@"
LD_LIBRARY_PATH= exec /data/bin/blob/play-audio "$@"
Problem is Path does not get passed correctly to play command over ssh. Path with multi spaces becomes single space and brackets create syntax error.
Example :
For file 18. Warriors.flac
present in /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015
Path sent to audioplay is correct :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
But the path received by play script is wrong :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
Multi spaces are turned into single space. Why ?
Then the main play-audio
binary gets only path /sdcard/Music/Imagine
upto first space only.
Example 2 ::
I tried with file having brackets :: 44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
Path received by audioplay script is correct :: /sdcard/Music/44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
But I get this error :: sh: syntax error: '(' unexpected
I tried with passing $@
$*
"$@"
and "$*"
. But none of them worked for me.
bash ssh filenames path arguments
add a comment |Â
up vote
3
down vote
favorite
I use Thunar file explorer and pass pathname and filename to a script audioplay. audioplay runs play command on my android via ssh which plays a song.
audioplay script :: cat audioplay
if [ $# -eq 1 ] ; then
echo " Playing..." "$@"
sshpass -p $passwd ssh root@192.168.43.10 -p $port play "$@"
else
echo " No Input audio file."
fi
play script on my android :: cat play
#!/data/bin/bash
# Avoid linker errors due to libOpenSLES.so:
echo "File ::" "$@"
LD_LIBRARY_PATH= exec /data/bin/blob/play-audio "$@"
Problem is Path does not get passed correctly to play command over ssh. Path with multi spaces becomes single space and brackets create syntax error.
Example :
For file 18. Warriors.flac
present in /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015
Path sent to audioplay is correct :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
But the path received by play script is wrong :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
Multi spaces are turned into single space. Why ?
Then the main play-audio
binary gets only path /sdcard/Music/Imagine
upto first space only.
Example 2 ::
I tried with file having brackets :: 44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
Path received by audioplay script is correct :: /sdcard/Music/44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
But I get this error :: sh: syntax error: '(' unexpected
I tried with passing $@
$*
"$@"
and "$*"
. But none of them worked for me.
bash ssh filenames path arguments
See How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?. Also remember to quote your variables
â Stéphane Chazelas
Sep 26 '17 at 15:30
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I use Thunar file explorer and pass pathname and filename to a script audioplay. audioplay runs play command on my android via ssh which plays a song.
audioplay script :: cat audioplay
if [ $# -eq 1 ] ; then
echo " Playing..." "$@"
sshpass -p $passwd ssh root@192.168.43.10 -p $port play "$@"
else
echo " No Input audio file."
fi
play script on my android :: cat play
#!/data/bin/bash
# Avoid linker errors due to libOpenSLES.so:
echo "File ::" "$@"
LD_LIBRARY_PATH= exec /data/bin/blob/play-audio "$@"
Problem is Path does not get passed correctly to play command over ssh. Path with multi spaces becomes single space and brackets create syntax error.
Example :
For file 18. Warriors.flac
present in /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015
Path sent to audioplay is correct :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
But the path received by play script is wrong :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
Multi spaces are turned into single space. Why ?
Then the main play-audio
binary gets only path /sdcard/Music/Imagine
upto first space only.
Example 2 ::
I tried with file having brackets :: 44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
Path received by audioplay script is correct :: /sdcard/Music/44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
But I get this error :: sh: syntax error: '(' unexpected
I tried with passing $@
$*
"$@"
and "$*"
. But none of them worked for me.
bash ssh filenames path arguments
I use Thunar file explorer and pass pathname and filename to a script audioplay. audioplay runs play command on my android via ssh which plays a song.
audioplay script :: cat audioplay
if [ $# -eq 1 ] ; then
echo " Playing..." "$@"
sshpass -p $passwd ssh root@192.168.43.10 -p $port play "$@"
else
echo " No Input audio file."
fi
play script on my android :: cat play
#!/data/bin/bash
# Avoid linker errors due to libOpenSLES.so:
echo "File ::" "$@"
LD_LIBRARY_PATH= exec /data/bin/blob/play-audio "$@"
Problem is Path does not get passed correctly to play command over ssh. Path with multi spaces becomes single space and brackets create syntax error.
Example :
For file 18. Warriors.flac
present in /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015
Path sent to audioplay is correct :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
But the path received by play script is wrong :: /sdcard/Music/Imagine Dragons - Smoke Mirrors -Deluxe Edition-2015/18. Warriors.flac
Multi spaces are turned into single space. Why ?
Then the main play-audio
binary gets only path /sdcard/Music/Imagine
upto first space only.
Example 2 ::
I tried with file having brackets :: 44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
Path received by audioplay script is correct :: /sdcard/Music/44. Go Tell Aunt Rhody -Resident Evil- (Short Version).flac
But I get this error :: sh: syntax error: '(' unexpected
I tried with passing $@
$*
"$@"
and "$*"
. But none of them worked for me.
bash ssh filenames path arguments
bash ssh filenames path arguments
asked Sep 26 '17 at 15:26
jonny789
8910
8910
See How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?. Also remember to quote your variables
â Stéphane Chazelas
Sep 26 '17 at 15:30
add a comment |Â
See How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?. Also remember to quote your variables
â Stéphane Chazelas
Sep 26 '17 at 15:30
See How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?. Also remember to quote your variables
â Stéphane Chazelas
Sep 26 '17 at 15:30
See How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?. Also remember to quote your variables
â Stéphane Chazelas
Sep 26 '17 at 15:30
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Quote it again:
if [ "$#" -eq 1 ] ; then
echo " Playing..." "$1"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play '$1'"
else
echo " No Input audio file."
fi
The thing is that the first layer of quotes, the "$@"
are expanded when you run the sshpass
command. So by the time you log in, launch the remote shell and execute play
, you have an unquoted string, so your script chokes on whitespace. By enclosing it in a second layer of quotes, you ensure that it is passed quoted to the remote command.
This should work assuming that i) the remote machine is running sh
or bash
or a similar shell and ii) your file names don't contain single quotes. To make it truly robust, please see How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?.
For properly quoting an arbitrary string (or even a list of arbitrary strings so you can pass more than one argument to play
) in the sh
syntax, we can use that shquote()
function mentioned there:
shquote()
LC_ALL=C awk -v q=' -v b='\' '
BEGIN
for (i=1; i<ARGC; i++)
gsub(q, q b q q, ARGV[i])
printf "%s ", q ARGV[i] q
print ""
exit
' "$@"
if [ "$#" -ge 1 ] ; then
echo " Playing..." "$@"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play $(shquote "$@")"
else
echo " No Input audio file."
fi
It would quote Sgt. Pepper's lonely hearts club band.flac
as 'Sgt. Pepper'''s lonely hearts club band.mp3'
which is correct for sh
(and evil';reboot;: '.flac
as 'evil''';reboot;: '''.flac'
instead of rebooting the remote machine (do you have to run that play
command as root
?)).
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is runningsh
. But yes, it will indeed break on single quotes.
â terdonâ¦
Sep 26 '17 at 15:36
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
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
Quote it again:
if [ "$#" -eq 1 ] ; then
echo " Playing..." "$1"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play '$1'"
else
echo " No Input audio file."
fi
The thing is that the first layer of quotes, the "$@"
are expanded when you run the sshpass
command. So by the time you log in, launch the remote shell and execute play
, you have an unquoted string, so your script chokes on whitespace. By enclosing it in a second layer of quotes, you ensure that it is passed quoted to the remote command.
This should work assuming that i) the remote machine is running sh
or bash
or a similar shell and ii) your file names don't contain single quotes. To make it truly robust, please see How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?.
For properly quoting an arbitrary string (or even a list of arbitrary strings so you can pass more than one argument to play
) in the sh
syntax, we can use that shquote()
function mentioned there:
shquote()
LC_ALL=C awk -v q=' -v b='\' '
BEGIN
for (i=1; i<ARGC; i++)
gsub(q, q b q q, ARGV[i])
printf "%s ", q ARGV[i] q
print ""
exit
' "$@"
if [ "$#" -ge 1 ] ; then
echo " Playing..." "$@"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play $(shquote "$@")"
else
echo " No Input audio file."
fi
It would quote Sgt. Pepper's lonely hearts club band.flac
as 'Sgt. Pepper'''s lonely hearts club band.mp3'
which is correct for sh
(and evil';reboot;: '.flac
as 'evil''';reboot;: '''.flac'
instead of rebooting the remote machine (do you have to run that play
command as root
?)).
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is runningsh
. But yes, it will indeed break on single quotes.
â terdonâ¦
Sep 26 '17 at 15:36
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
add a comment |Â
up vote
2
down vote
accepted
Quote it again:
if [ "$#" -eq 1 ] ; then
echo " Playing..." "$1"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play '$1'"
else
echo " No Input audio file."
fi
The thing is that the first layer of quotes, the "$@"
are expanded when you run the sshpass
command. So by the time you log in, launch the remote shell and execute play
, you have an unquoted string, so your script chokes on whitespace. By enclosing it in a second layer of quotes, you ensure that it is passed quoted to the remote command.
This should work assuming that i) the remote machine is running sh
or bash
or a similar shell and ii) your file names don't contain single quotes. To make it truly robust, please see How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?.
For properly quoting an arbitrary string (or even a list of arbitrary strings so you can pass more than one argument to play
) in the sh
syntax, we can use that shquote()
function mentioned there:
shquote()
LC_ALL=C awk -v q=' -v b='\' '
BEGIN
for (i=1; i<ARGC; i++)
gsub(q, q b q q, ARGV[i])
printf "%s ", q ARGV[i] q
print ""
exit
' "$@"
if [ "$#" -ge 1 ] ; then
echo " Playing..." "$@"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play $(shquote "$@")"
else
echo " No Input audio file."
fi
It would quote Sgt. Pepper's lonely hearts club band.flac
as 'Sgt. Pepper'''s lonely hearts club band.mp3'
which is correct for sh
(and evil';reboot;: '.flac
as 'evil''';reboot;: '''.flac'
instead of rebooting the remote machine (do you have to run that play
command as root
?)).
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is runningsh
. But yes, it will indeed break on single quotes.
â terdonâ¦
Sep 26 '17 at 15:36
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Quote it again:
if [ "$#" -eq 1 ] ; then
echo " Playing..." "$1"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play '$1'"
else
echo " No Input audio file."
fi
The thing is that the first layer of quotes, the "$@"
are expanded when you run the sshpass
command. So by the time you log in, launch the remote shell and execute play
, you have an unquoted string, so your script chokes on whitespace. By enclosing it in a second layer of quotes, you ensure that it is passed quoted to the remote command.
This should work assuming that i) the remote machine is running sh
or bash
or a similar shell and ii) your file names don't contain single quotes. To make it truly robust, please see How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?.
For properly quoting an arbitrary string (or even a list of arbitrary strings so you can pass more than one argument to play
) in the sh
syntax, we can use that shquote()
function mentioned there:
shquote()
LC_ALL=C awk -v q=' -v b='\' '
BEGIN
for (i=1; i<ARGC; i++)
gsub(q, q b q q, ARGV[i])
printf "%s ", q ARGV[i] q
print ""
exit
' "$@"
if [ "$#" -ge 1 ] ; then
echo " Playing..." "$@"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play $(shquote "$@")"
else
echo " No Input audio file."
fi
It would quote Sgt. Pepper's lonely hearts club band.flac
as 'Sgt. Pepper'''s lonely hearts club band.mp3'
which is correct for sh
(and evil';reboot;: '.flac
as 'evil''';reboot;: '''.flac'
instead of rebooting the remote machine (do you have to run that play
command as root
?)).
Quote it again:
if [ "$#" -eq 1 ] ; then
echo " Playing..." "$1"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play '$1'"
else
echo " No Input audio file."
fi
The thing is that the first layer of quotes, the "$@"
are expanded when you run the sshpass
command. So by the time you log in, launch the remote shell and execute play
, you have an unquoted string, so your script chokes on whitespace. By enclosing it in a second layer of quotes, you ensure that it is passed quoted to the remote command.
This should work assuming that i) the remote machine is running sh
or bash
or a similar shell and ii) your file names don't contain single quotes. To make it truly robust, please see How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?.
For properly quoting an arbitrary string (or even a list of arbitrary strings so you can pass more than one argument to play
) in the sh
syntax, we can use that shquote()
function mentioned there:
shquote()
LC_ALL=C awk -v q=' -v b='\' '
BEGIN
for (i=1; i<ARGC; i++)
gsub(q, q b q q, ARGV[i])
printf "%s ", q ARGV[i] q
print ""
exit
' "$@"
if [ "$#" -ge 1 ] ; then
echo " Playing..." "$@"
sshpass -p "$passwd" ssh root@192.168.43.10 -p "$port" "play $(shquote "$@")"
else
echo " No Input audio file."
fi
It would quote Sgt. Pepper's lonely hearts club band.flac
as 'Sgt. Pepper'''s lonely hearts club band.mp3'
which is correct for sh
(and evil';reboot;: '.flac
as 'evil''';reboot;: '''.flac'
instead of rebooting the remote machine (do you have to run that play
command as root
?)).
edited Sep 26 '17 at 15:54
Stéphane Chazelas
284k53523859
284k53523859
answered Sep 26 '17 at 15:33
terdonâ¦
123k28232404
123k28232404
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is runningsh
. But yes, it will indeed break on single quotes.
â terdonâ¦
Sep 26 '17 at 15:36
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
add a comment |Â
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is runningsh
. But yes, it will indeed break on single quotes.
â terdonâ¦
Sep 26 '17 at 15:36
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is running
sh
. But yes, it will indeed break on single quotes.â terdonâ¦
Sep 26 '17 at 15:36
@StéphaneChazelas since it's an Android device, it's safe (I think) to assume the remote is running
sh
. But yes, it will indeed break on single quotes.â terdonâ¦
Sep 26 '17 at 15:36
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
It worked. Thanks a lot. I spent hours on it searching and trying.
â jonny789
Sep 26 '17 at 15:41
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
@jonny789 you're welcome. But do read Stéphane's answer in the linked post for more detail.
â terdonâ¦
Sep 26 '17 at 15:44
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
Yes. I login to android as root user. Running play as root works without any issue.
â jonny789
Sep 26 '17 at 17:06
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%2f394568%2fproblem-with-passing-path-containing-spaces-and-brackets%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
See How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?. Also remember to quote your variables
â Stéphane Chazelas
Sep 26 '17 at 15:30