I am getting an unexpected end of file error after including this line in my .bashrc
alias domsrv01='echo -e ?HT_R8\'% | xclip ; ssh 10.50.0.35'
The desired exit from echo to xclip is:
?HT_R8'%
As you may guess, it's a password and I can't change it so:
How can I escape the single quote character from inside the password to fix the EOF error?
Also, I'm not sure if the single quote is the only issue here, can "?" and "%" be interpreted in funny ways too?
You cannot directly escape singe quotes within single quotes in bash. However, since bash concatenates adjacent strings, you can use this construct instead 'text'"'"'moretest'
. You actually end the single quoted string with a single quote, and immediately add a double quoted single quote, followed by the remaining of the string (in single quotes). In your specific example, the command would look like this:
alias domsrv01='echo -e ?HT_R8\'"'"'% | xclip ; ssh 10.50.0.35'
More discussion on the topic can be fount here: How to escape single-quotes within single-quoted strings?
Edited: Added the missing backlash noticed by @GordonDavisson