bash - 使用 bash 回显时,某些值不会被复制

标签 bash ubuntu

我想将所有这些回显到文件中:

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/

相关文章:

ruby-on-rails - 在系统启动时启动 Sidekiq。 Ubuntu 14.04

php - 更改 php.ini 似乎没有效果

audio - 如何配置 JACK 音频服务器以自动使用特定的卡?

bash - 如何将php(及其stderr)中的exec调用的输出重定向到调用程序?

python - 在 Ubuntu18.04 中使用 CUDA 使用 Python 库 Keops 的运行时错误

linux - 如何创建类似 $RANDOM 的 bash 变量

linux - 如何在 Bash 脚本中逐行读取文件?

linux - 前缀搜索名称以在 bash 中输出

bash - 使bash脚本切换到交互模式并给出提示

python - 如何从Python实时读取终端输出?