Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to <em>Sahas</em>, I managed to achieve the following solution:</p> <pre><code>function log() { [ -z "$counter" ] &amp;&amp; counter=1 || (( ++counter )) if [ -n "$teepid" ]; then exec 1&gt;&amp;- 2&gt;&amp;- # close file descriptors to signal EOF to the `tee` # command in the bg process wait $teepid # wait for bg process to exit fi # Display text-to-be-logged on screen and # write it to the summary log &amp; to it's corresponding log file ( tee "${counter}.log" &lt; "$pipe" | tee -a "Summary.log" 1&gt;&amp;4 ) &amp; teepid=$! exec 1&gt;"$pipe" 2&gt;&amp;1 # redirect stdout &amp; stderr to the pipe } # Create temporary FIFO/pipe pipe_dir=$(mktemp -d) pipe="${pipe_dir}/cmds_output" mkfifo "$pipe" exec 4&lt;&amp;1 # save value of FD1 to FD4 log # Logs the following code block { # ... Many bash commands ... } log # Logs the following code block { # ... Many bash commands ... } if [ -n "$teepid" ]; then exec 1&gt;&amp;- 2&gt;&amp;- # close file descriptors to signal EOF to the `tee` # command in the bg process wait $teepid # wait for bg process to exit fi </code></pre> <p><strong>It works - I tested it.</strong></p> <p>References:</p> <ul> <li><a href="https://superuser.com/questions/86915/force-bash-script-to-use-tee-without-piping-from-the-command-line">Force bash script to use tee without piping from the command line @ superuser.com</a> - <strong>helped a lot</strong></li> <li><a href="http://tldp.org/LDP/abs/html/io-redirection.html" rel="nofollow noreferrer">I/O Redirection @ tldp.org</a></li> <li><a href="http://tldp.org/LDP/abs/html/internalvariables.html#PIDVARREF" rel="nofollow noreferrer">$! - PID Variable @ tldp.org</a></li> <li><a href="http://tldp.org/LDP/abs/html/refcards.html#AEN22078" rel="nofollow noreferrer">TEST Operators: Binary Comparison @ tldp.org</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload