Home kBayes

Bash code snippets

Date written Jul 5, 2020
Date updated Last updated: May 3, 2021
Filed under Software Eng. in tech

Contents
  • Articles
  • Snippets

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
)