summaryrefslogtreecommitdiff
path: root/3 Resources/Bash
diff options
context:
space:
mode:
Diffstat (limited to '3 Resources/Bash')
-rw-r--r--3 Resources/Bash/Expansion.md9
-rw-r--r--3 Resources/Bash/Generate random integers.md19
-rw-r--r--3 Resources/Bash/Heredoc.md16
3 files changed, 44 insertions, 0 deletions
diff --git a/3 Resources/Bash/Expansion.md b/3 Resources/Bash/Expansion.md
new file mode 100644
index 0000000..1cd3209
--- /dev/null
+++ b/3 Resources/Bash/Expansion.md
@@ -0,0 +1,9 @@
+---
+tags:
+ - bash
+---
+Find about in the manual `man bash` (search EXPANSION). This document will hold some often used expansions.
+
+**Variable expansion**
+substr
+`${VAR:offset:len}` \ No newline at end of file
diff --git a/3 Resources/Bash/Generate random integers.md b/3 Resources/Bash/Generate random integers.md
new file mode 100644
index 0000000..8835716
--- /dev/null
+++ b/3 Resources/Bash/Generate random integers.md
@@ -0,0 +1,19 @@
+---
+tags:
+ - bash
+---
+The environment variable `RANDOM` contains an int between 0-32768.
+
+```
+min=10
+max=20
+echo $(($RANDOM%($max-$min+1)+$min))
+20
+echo $(($RANDOM%($max-$min+1)+$min))
+14
+```
+
+Using parameter [[Expansion]] we can just grab the first number:
+```
+${RANDOM:0}
+``` \ No newline at end of file
diff --git a/3 Resources/Bash/Heredoc.md b/3 Resources/Bash/Heredoc.md
new file mode 100644
index 0000000..703e3e5
--- /dev/null
+++ b/3 Resources/Bash/Heredoc.md
@@ -0,0 +1,16 @@
+```
+read -r -d '' VAR <<EOF
+blaat
+EOF
+```
+
+```
+var=$(
+cat <<EOF
+blaat
+EOF
+)
+```
+
+Quote EOF/NAME to prevent expansion
+Put - after << to remove indentation from result \ No newline at end of file