title: How can I build a dynamic parameter list for mailx command in bash linux?
body: <p>OS:  Red Hat Enterprise Linux Server release 5.11 (Tikanga)</p>
  
  <p>I have a code sniplet:</p>
  
  <pre><code>!/usr/bin/env bash
  
  v_mailx_parameter=""
  
  v_cfg_email_adresse_to="john.doe_to@gmail.com"
  v_cfg_email_subject="Report from December 2016"
  v_tmp_email_text_name="Message Body"
  
  v_email_main_file="appel orange.txt" # -&gt; 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
  </code></pre>
  
  <p>PROBLEM:
  I want to build up the parameters to the mailx command dynamically.</p>
  
  <p>But I want to use the " double-quotes because there can be spaces in the file names.</p>
  
  <p>Unfortunately the example above does not work... because the mailx takes the double-quotes as if they belong to the file name...and I get an error message.</p>
  
  <p>I do not want to use the if else condition.. because I have many of files I need to send... I need a dynamic solution.</p>
  
  <p>Maybe it is better to understand what my problem is:</p>
  
  <p>It works in such a hardcoded way:</p>
  
  <pre><code>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}"
  </code></pre>
  
  <p>But so NOT:</p>
  
  <pre><code>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}"
  </code></pre>
  
  <p>Thanks!</p>