I don't know how to print a variable inside a string of a string.
I first started off without a variable like this and it worked perfectly:
#!/bin/bash
ssh 1.1.1.1 $'sudo -H -u apache bash -c \'cd ~/html; echo development > stuff.text\''
When I login to my server at 1.1.1.1, I can see that the file stuff.text has the word development. Perfect.
Then I made this bash script:
#!/bin/bash
BRANCH=development
ssh 1.1.1.1 $'sudo -H -u apache bash -c \'cd ~/html; echo ${BRANCH} > stuff.text\''
But running this bash script causes an empty stuff.text file. I also tried each of these commands, but they all gave syntax/parse errors:
ssh 1.1.1.1 $`sudo -H -u apache bash -c 'cd ~/html; echo ${BRANCH} > stuff.text'`
ssh 1.1.1.1 ${`sudo -H -u apache bash -c 'cd ~/html; echo ${BRANCH} > stuff.text'`}
ssh 1.1.1.1 ${sudo -H -u apache bash -c 'cd ~/html; echo ${BRANCH} > stuff.text'}
ssh 1.1.1.1 ${"sudo -H -u apache bash -c 'cd ~/html; echo ${BRANCH} > stuff.text'"}
How do I write a variable inside the string of another string?
ssh 1.1.1.1 $'sudo -H -u apache bash -c \'cd ~/html; echo development > stuff.text\''? You cannot escape single quotes, this is just a very complex notation to do something actually quite simple. Please edit your question and explain what you are trying to do.'...', but you can within a$'...'. Of course the syntax highlighting doesn't know it here.$'...'at all, but that's a different issue.