2017-08-02 81 views
1

我想讓bash的報價"沒有解釋慶典使報價沒有解釋轉義

更超過我想exec後面在bash

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

命令行,我要儘量包裹,在bash腳本像這樣的:

#!/bin/bash 
# -*- coding: utf-8 -*- 

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

和EXEC這樣

0123的上式bashscript

但它顯示了這一點:

+ gnuplot -e 'filename=\'\''data.dat\'\''' plot.gnuplot 

filename=\'data.dat\' 
     ^
line 0: invalid character \ 

如何做到這一點?

+0

爲什麼你在bash腳本中使用python編碼嗎? –

+0

@ l'l l告訴vim默認的編碼 – armnotstrong

+0

我看到了;也許嘗試在命令之前設置你的文件名變量(例如''filename ='''{1}'「'然後'gnuplot -e」$ filename「plot.gnuplot' ... –

回答

1

儘量提前命令設置變量:

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

如果報價必須是圍繞變量:

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

設置變量作爲一個命令:

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