2013-03-19 110 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