代码之家  ›  专栏  ›  技术社区  ›  armnotstrong

bash make quote未解释转义

  •  1
  • armnotstrong  · 技术社区  · 7 年前

    "

    我想在bash中执行以下命令行

    gnuplot -e "filename='data.dat'" plot.gnuplot
    

    我尝试用bash脚本将其包装如下:

    #!/bin/bash
    # -*- coding: utf-8 -*-
    
    gnuplot -e "filename=\'${1}\'" plot.gnuplot
    

    bash -x plot.sh data.dat
    

    但它表明:

     + gnuplot -e 'filename=\'\''data.dat\'\''' plot.gnuplot
    
    filename=\'data.dat\'
             ^
    line 0: invalid character \
    

    怎么做?

    1 回复  |  直到 7 年前
        1
  •  1
  •   l'L'l    7 年前

    尝试在命令之前设置变量:

    path="filename='${1}'"
    gnuplot -e "$path" plot.gnuplot
    

    如果需要在变量周围加引号:

    path="\"filename='${1}'\""
    gnuplot -e "$path" plot.gnuplot
    

    gnuplot -e "\"filename='${1}'\"" plot.gnuplot