OS : 레드햇 엔터프라이즈 리눅스 서버는 5.11 (Tikanga)bash linux에서 mailx 명령에 대한 동적 매개 변수 목록을 작성하려면 어떻게해야합니까?
내가 코드 스니 플릿을 해제 :
!/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}"
감사합니다!
자세한 내용은 [BashFAQ # 50] (http://mywiki.wooledge.org/BashFAQ/050)에 나와 있습니다. –