Problem escaping single quote when using /usr/bin/expect -c
Hi all,
I'm using CHEF to automate the environment of my VPS. My wish is now to create a MySQL user. To prevent passing the MySQL-password as a command line arg I'm using /usr/bin/expect. This seems to be more complicated than I thought. Without CHEF and expect I would to: Code:
mysql -uroot -p Code:
bash "create-mysql-user" do Going through the log I see, that the single quotes around the passwords get removed. Now: Whatever I tried, I couldn't get the single quotes in the final output. I tried:
So my question is: How can I use /usr/bin/expect with "-c" AND single quotes? Thanks in advance and best regards |
Passing a literal single quote inside a single-quoted string is a bit tricky. Since the backslash character is not special inside that string, what you have to do is end the string with a single quote, then put in the escaped single quote, then continue the single-quoted string.
Code:
echo 'You can'\''t do this easily' What it boils down to is representing each literal single quote with the 4-character sequence '\'' . |
Thank you rknichols
that solved my question. Code:
/usr/bin/expect -c 'send "This is a '\''test:'\''"' Code:
This is a 'test' Therefore I've posted now on the chef-mailing-list. Best regards |
All times are GMT -5. The time now is 01:51 AM. |