2013-03-19 41 views
3

如果我想用它的變量來執行命令,我總是要首先存儲在字符串中的一個變量,然後才能執行它...的Linux Shell腳本執行不保存到臨時變量

例子:

path_fasta="/home/xxx/yyy/zzz/qqq/" 
name_fasta="CTA_Mix_DNA.fna" 
path_outp"/some/Path/" 

temp='find . -maxdepth 1 -not -name '$name_fasta' -not -name letsgo.sh -delete' 
$temp 

temp=$path_mothur'mothur #set.dir(output='$path_outp');summary.seqs(fasta='$path_fasta''$name_fasta')' 
$temp 

如何直接執行此操作而不是先將其存儲在臨時文件中?必須是容易的,但是沒有找到解決的辦法......

回答

5

相反的:

temp='find . -maxdepth 1 -not -name '$name_fasta' -not -name letsgo.sh -delete' 
$temp 

...只需使用:

find . -maxdepth 1 -not -name "$name_fasta" -not -name letsgo.sh -delete 
+0

謝謝,這解決了我的問題! – Michael 2013-03-19 18:23:26

+0

爲什麼字面單引號?如果變量的值包含一個單引號,那麼就會出現問題。爲什麼不只是雙引號變量? – 2013-03-19 20:40:25

+0

根據@ glennjackman的建議編輯。 – 2013-03-19 21:53:09