argos icon indicating copy to clipboard operation
argos copied to clipboard

apostrophe in bash command

Open plegrand1 opened this issue 5 years ago • 3 comments

Hello, i've got a problem to use argos when i need to write an apostrophe inside a bash command. I can't escape it : echo "rdesktop | bash='/usr/bin/rdesktop -u user -p p'assword 192.168.151.239'"

here, there is an apostrophe inside password, what is the way to escape it ?

Thanks for your extension and for your help;

plegrand1 avatar Nov 06 '18 15:11 plegrand1

In Bash it is not possible to escape any character inside single quotes '...'. I'm not sure what your code is trying to do, but (I think) you could write the same code by nested, escaped double-quotes " ... \" \' \" ... "

# using read + echo for testing
echo "$(echo a | bash -c "read; echo -- \$REPLY -u user -p p\'assword 192.168.151.239\'" )"
# prints: -- a -u user -p p'assword 192.168.151.239'

# to prove it is doing what (i suspect) it should
#!/bin/bash
# x is an array
declare -a x=("$(echo a | bash -c "read; echo -- \$REPLY -u user -p p\'assword 192.168.151.239\'" )")
echo "${x[*]}" # the whole array
echo ${x[0]} # the first element: the whole string
echo ${x[1]} # the second element: nothing

I don't have or know how to use rdesktop so hopefully you can replace echo -- with /usr/bin/rdesktop

Also, setting bash= does not run the string, it simply puts the string into a variable bash, which I think isn't what you want.

However this has nothing to do with Argos, your code isn't valid Bash in the first place. If you have further questions about Bash syntax / scripting see

https://unix.stackexchange.com http://mywiki.wooledge.org/ (the bash sections) http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html

catb0t avatar Nov 06 '18 18:11 catb0t

As my problem was the password, i solved my problem by using secret-tool to store this password

secret-tool store --label 'rDesktop' user Admin then the bash command line become : secret-tool lookup user Admin | rdesktop -u Admin -p - 192.168.1.1'"

plegrand1 avatar Nov 08 '18 07:11 plegrand1

Also, setting bash= does not run the string, it simply puts the string into a variable bash, which I think isn't what you want.

That's not quite valid for argos. The syntax used by @plegrand1 is absolutely valid here.

I think [...] you could write the same code by nested, escaped double-quotes " ... " ' " ... "

Absolutely! You do not even have to escape those. I use it like this:

# >> --------------------------------------------------v----v
echo "--<span color='#faff00'>${l}</span> | bash=\"ssh '${l}'; exit\""

boppy avatar Dec 23 '18 16:12 boppy