Linux Shell脚本执行时不需要保存到临时变量中

3
如果我想执行一个带有变量的命令,我总是需要先将字符串存储在一个变量中,然后才能执行它...
例如:
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

我怎样才能直接做到这一点,而不必先将其存储在临时文件中?可能很简单,但我没有找到解决方案...
1个回答

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

为什么要使用单引号?如果变量的值包含单引号,那就会出问题了。为什么不直接用双引号来引用变量呢? - glenn jackman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接