我有一个代码sniplet:
!/usr/bin/env bash
v_mailx_parameter=""
v_cfg_email_adresse_to="[email protected]"
v_cfg_email_subject="Report from December 2016"
v_tmp_email_text_name="Message Body"
v_email_main_file="appel orange.txt" # -> There is a SPACE in the file name!
v_tmp_path="/home/server/tmp/"
if [ ! -z "${v_email_main_file}" ]
then v_mailx_parameter="${v_mailx_parameter} -a \"${v_tmp_path}${v_email_main_file}\""
/\
||
Here is the problem but I need this because of spaces in the name
fi
echo -e "/bin/mailx ${v_mailx_parameter} -s \"${v_cfg_email_subject}\" \"${v_cfg_email_adresse_to}\""
cat ${v_tmp_email_text_name} | /bin/mailx ${v_mailx_parameter} -s "${v_cfg_email_subject}" "${v_cfg_email_adresse_to}"
exit
问题: 我要动态建立的参数mailx命令来。
但我想用“双引号,因为可以有在文件名称中使用空格。
不幸的是上面的例子中不起作用......因为mailx的采用双引号,就好像它们属于到文件名...我得到一条错误信息
我不想使用if else条件..因为我有很多需要发送的文件...我需要动态解决方案
也许最好理解我的问题是什么:
它工作在这样的硬编码方式:
cat ${v_tmp_email_text_name} | /bin/mailx -a "/home/server/tmp/appel orange.txt" -s "${v_cfg_email_subject}" "${v_cfg_email_adresse_to}"
但所以不是:
v_mailx_parameter="-a \"${v_tmp_path}${v_email_main_file}\""
cat ${v_tmp_email_text_name} | /bin/mailx ${v_mailx_parameter} -s "${v_cfg_email_subject}" "${v_cfg_email_adresse_to}"
谢谢!
+0
这在[BashFAQ#50](http://mywiki.wooledge.org/BashFAQ/050)中有详细介绍。 –