Bash code snippets

🚀 tech

Table of Contents

Articles

Snippets

Script Directory

To get the absolute path to directory in which the bash script resides

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

Multiline strings

Always forgetting this very important utility.

strvar=$(cat << EOF

# all content goes here, bash variables work.

EOF
)

To directly put the output into a file

cat << EOF > /path/to/file

# all content goes here, bash variables work.

EOF
)