Poop Sheet

Heredocs

#!/usr/bin/bash

# MultiLine Comments With HereDoc using the no-op command (:).
: << COMMENTS
As you may already know, Bash does not support multi-line comments. 
Using heredoc, you can create multi-line comments by redirecting the block of code to the no-op command (:).

The no-op is bash built-in which takes the input and returns exit code zero. 
You can consider this as a synonym to the bash built-in "true" which also exits exit code zero.
COMMENTS


ExampleGroup 'heredocs'

  Example 'Printing MultiLine String Using HereDoc'
    function eg1() {
cat << EOF
Something is wrong with the input file received for today.
Contact the downstream team to get it corrected.
==> SLA MISSED <==
EOF
    }
    When call eg1
    The output line 1 should match pattern "Something is wrong with the input file received for today."
    The output line 2 should match pattern "Contact the downstream team to get it corrected."
    The output line 3 should match pattern "==> SLA MISSED <==" 
  End

  Example 'Tab Suppression In HereDoc'
    function eg2() {
cat <<- EOF
		Something is wrong with the input file received for today.
		Contact the downstream team to get it corrected.
		==> SLA MISSED <==
EOF
    }
    When call eg2
    The output line 1 should match pattern "Something is wrong with the input file received for today."
    The output line 2 should match pattern "Contact the downstream team to get it corrected."
    The output line 3 should match pattern "==> SLA MISSED <==" 
  End


End