title: Handling logs of bash script and comments in text file
body: <p>I am trying to read a text file which has few commented starts with '#', my bash script should read the lines of the text file which doesn't start with '#'. 
  Also im trying to capture the output of echo statements in both logs and to show it console window for the user understanding. </p>
  
  <p>I have tried to use the below query for capturing logs and printing in console</p>
  
  <p>exec 2>&amp;1 1>>$logfile</p>
  
  <p>For reading each line of the file and calling the function, i have declared an array and to eliminate lines which starts with '#' , i have used the below query.</p>
  
  <pre><code>declare -a cmd_array 
  while read -r -a cmd_array | grep -vE '^(\s*$|#)' 
  do
    "${cmd_array[@]}" 
  done &lt; "$text_file"
  </code></pre>
  
  <p>Note : I need to eliminate the line starts with '#' and remaining lines to be read and place in array as declared.</p>
  
  <pre><code>Bash script 
  ***********
  
  #! /bin/bash
  
  Function_1()
  {
  now=$( date '+%Y%m%d%H%M' )
  eval logfile="$1"_"$now".log
  exec 2&gt;&amp;1 1&gt;&gt;$logfile     ### Capture echo output in log and printing in console 
  #exec 3&gt;&amp;1 1&gt;&gt;$logfile 2&gt;&amp;1
  echo " "
  echo "############################"
  echo "Function execution Begins"
  echo "############################"
  echo "Log file got created with file name as $1.log"
  eval number=$1
  eval  path=$2
  echo "number= $number"
  ls -lR $path &gt;&gt; temp.txt
          if [ $? -eq 0 ]; then
          echo " Above query executed."
          else
          echo "Query execution failed"
          fi
  echo "############################"
  echo "Function execution Ends"
  echo "############################"
  echo " "
  }
  
  text_file=$1
  echo $text_file
  declare -a cmd_array  ### declaring a array 
  while read -r -a cmd_array | grep -vE '^(\s*$|#)'  ### Read each line in the file with doesnt starts with '#' &amp; keep it in array
  do
    "${cmd_array[@]}" 
  done &lt; "$text_file"
  
  
  Text file 
  *********
  ####################################    
  #Test
  #Line2
  ####################################
  Function_1 '125' '' ''
  Function_1 '123' '' ''
  </code></pre>