0

I am doing everything in a bash file. I am grabbing to variables from a parameter:

brand="$1"
email="$2"

Afterwards, I want to include on of them inside of a string:

 cd /etc/nginx/sites-available/

 echo 'server {
    listen       80;
    server_name  $brand.mydomain.com;
    root         /srv/www/clients/$brand/soon;
 }' >> default

But it echo's $brand.mydomain.com. How to echo the actual value which I am passing as parameter?

1
  • 4
    Use double quotes instead of single quote in echo. Commented Jan 23, 2016 at 21:26

1 Answer 1

1

Single quotes don't allow for expansion of anything. Double quotes allow for expansion of variable, but you best enclose the name with parenthesis as shown.

echo "server {
    listen       80;
    server_name  ${brand}.mydomain.com;
    root         /srv/www/clients/${brand}/soon;
}" >> default
Sign up to request clarification or add additional context in comments.

1 Comment

No need for the braces here. The . and the / characters are not valid variable name characters so they terminate the name. The practice of enclosing with braces is often needed in csh where the expansions are different, but only in bash when surrounded by alphanumerics or underscores.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.