skip to Main Content

I have a script. I can’t print $ in a screen.

#!/bin/bash

SERVER_IP=""
PASSWORD=""
DOMAIN=""
CONFIG_CONTENT=$(cat << EOF

server {
    listen 80;
    listen [::]:80;

    root /home/webmas/$DOMAIN;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name $DOMAIN;

    location / {
            try_files $uri $uri/ =404;
    }

    location ~ .php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /.ht {
            deny all;
    }
}

EOF
)

ssh -tt -p 300 webmas@$SERVER_IP << EOF

mkdir $DOMAIN
cd /etc/nginx/sites-available
echo -n "$PASSWORD" | sudo -S sh -c "echo '$CONFIG_CONTENT' | tee /etc/nginx/sites-  available/$DOMAIN >/dev/null"

EOF

$uri is not displayed on the screen

I don’t understand why $ don’t help. Single quotes didn’t help either. I’ve run out of ideas.

2

Answers


  1. Use the quoted way on here document:

    foobar<<'EOF'
    $XYZ
    EOF
    
    Login or Signup to reply.
  2. I hope this Inspired answer by @GillesQuénot help.
    Try this answer using double quotes around the HERE documents:

    #!/bin/bash
    
    SERVER_IP=""
    PASSWORD=""
    DOMAIN=""
    CONFIG_CONTENT=$(cat << "EOF"
    server {
        listen 80;
        listen [::]:80;
    
        root /home/webmas/$DOMAIN;
    
        index index.php index.html index.htm index.nginx-debian.html;
    
        server_name $DOMAIN;
    
        location / {
                try_files $uri $uri/ =404;
        }
    
        location ~ .php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }
    
        location ~ /.ht {
                deny all;
        }
    }
    EOF
    )
    
    ssh -tt -p 300 webmas@$SERVER_IP << EOF
    
    mkdir $DOMAIN
    cd /etc/nginx/sites-available
    echo -n "$PASSWORD" | sudo -S sh -c "echo '$CONFIG_CONTENT' | tee /etc/nginx/sites-available/$DOMAIN >/dev/null"
    
    EOF
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search