我有一个variables,我这样构build:
ATTSTR="" for file in $LOCALDIR/*.pdf do ATTSTR="${ATTSTR} -a \"${file}\"" done
variables现在包含(注意文件名中的空格):
ATTSTR=' -a "/tmp/Testpage - PDFCreator.pdf"'
现在我想在这个命令中使用这个variables:
mutt -s "Subject" "${ATTSTR}" [email protected]
但事实certificate,它是这样扩展,因此命令失败(注意扩展variables周围的单引号):
mutt -s "Subject" ' -a "/tmp/Testpage - PDFCreator.pdf"' [email protected]
我希望我的variables扩展没有单引号,使用"$ATTSTR"
或$ATTSTR
只是更糟。 我怎样才能做到这一点?
扩展string中的文件名是不可靠的; 抵制这种诱惑。
相反,使用一个数组来保持文件名不变,而不pipe任何空格:
arr=() for f in $somedir/*.pdf do arr+=( -a "$f") done # and for usage/display: mutt -s mysubject "${a[@]}" some@body
请参阅arrays上的Bash指南以供参考。