From 9d7447e6a4805587529afd68dff049ed9488c2a0 Mon Sep 17 00:00:00 2001 From: Marcus Lugg Date: Sun, 7 Oct 2018 12:50:27 +0100 Subject: [PATCH] DOC: Add bash heredocs and file existence flags --- docs/useful_commands/bash.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/useful_commands/bash.md b/docs/useful_commands/bash.md index a8dbb6f..1ac3530 100644 --- a/docs/useful_commands/bash.md +++ b/docs/useful_commands/bash.md @@ -15,6 +15,9 @@ | `$USERNAME` | Logged-in username | | `$HOME` | Home directory path | | `$BASH_VERSION` | Shell version | +| `[[ -d directory ]]` | Test a directory exists | +| `[[ -f file ]]` | Test a file exists | +| `[[ -e file_or_directory ]]` | Test for existence of file or directory | Colours in bash: [guide](https://gist.github.com/vratiu/9780109) @@ -168,3 +171,29 @@ Function return values can be accessed and assigned to a variable via command su ```bash output=$( my_function arg1 arg2 ... ) ``` + +## HereDocs +```bash +command << delimiter +line1 +line2 +line3 +delimiter +``` + +Ignore tabs by using `-`, e.g.: +```bash +cat <<- EOF + line1 + line2 + line3 +EOF +``` + +Send to a file: +```bash +cat > myfile <<- xxx + Content + More content +xxx +```