這就是我nginx.conf通過 shell創建檔案 ( ) 的方式。由于$我正在使用的檔案內容中有字符EOF。
if [ $type == "nginx" ]; then
cat > ${path}/nginx.conf <<'EOF'
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
include /etc/nginx/extra-conf.d/*.conf;
}
EOF
fi
現在我必須使用動態埠值,所以listen 3000我不需要使用listen $port. 但這不起作用,因為在內容中還有$uri,它應該作為文本處理,而不是作為變數處理。
uj5u.com熱心網友回復:
僅使用分隔符本身,要么擴展所有引數,要么不擴展所有引數。您必須允許擴張,但要避開美元符號$uri以抑制其擴張。
if [ "$type" = "nginx" ]; then
cat > "${path}/nginx.conf" <<EOF
server {
listen $port;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files \$uri \$uri/ /index.html = 404;
}
include /etc/nginx/extra-conf.d/*.conf;
}
EOF
fi
here 檔案的行為類似于雙引號字串:
$ foo=bar
$ echo "$foo"
bar
$ echo "\$foo"
$foo
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/315306.html
