我想将所有这些回显到文件中:
echo "server {
listen 80;
server_name mydomain.com;
root /srv/www/clients/;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/finance-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}" >> default
但所有包含美元符号的值(如 $query_string; 或 $document_root$fastcgi_script_name;)都被删除。是否有可能以某种方式逃避它,以便所有这些值也将保留到文件中?
最佳答案
您应该使用单引号来防止参数扩展,或者您可以使用 here-doc:
cat <<'EOF' > default
$query_string
$document_root
$fastcgi_script_name
EOF
(或
>> default
,如果你想追加)。注意 'EOF'
被引用以防止参数扩展。
关于bash - 使用 bash 回显时,某些值不会被复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35107446/