summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--A nice way to select IPv4 addresses with JQ.md (renamed from Examples of proper JQ usage.md)2
-rw-r--r--Bash process substition (tmp file).md13
-rw-r--r--Bash.md6
-rw-r--r--Building a command-line using arrays.md34
-rw-r--r--Globbing patterns.md3
-rw-r--r--Heredoc.md23
-rw-r--r--Nova compute evacuation.md10
-rw-r--r--Null substitution.md25
-rw-r--r--Parameter subsitution.md8
-rw-r--r--Process substition (tmp file).md15
-rw-r--r--Setting traps.md10
-rw-r--r--Shell.md5
-rw-r--r--daily/20-May-2025.md0
-rw-r--r--daily/27-May-2025.md4
14 files changed, 144 insertions, 14 deletions
diff --git a/Examples of proper JQ usage.md b/A nice way to select IPv4 addresses with JQ.md
index 2b68d01..b8f751d 100644
--- a/Examples of proper JQ usage.md
+++ b/A nice way to select IPv4 addresses with JQ.md
@@ -6,7 +6,7 @@ tags:
Double escapes are important!
```
-jq -r '.fixed_ips[] | select(.ip_address | test("\\.")) | .ip_address'
+jq -r '.fixed_ips[] | select(.ip_address | test("([0-9]+\\.)+")) | .ip_address'
```
An example of constructing an array from stdin and filtering empty lines is found in [[Using JQ to construct an array and filtering empty strings]]. \ No newline at end of file
diff --git a/Bash process substition (tmp file).md b/Bash process substition (tmp file).md
deleted file mode 100644
index 3540f70..0000000
--- a/Bash process substition (tmp file).md
+++ /dev/null
@@ -1,13 +0,0 @@
----
-tags:
- - bash
- - howto
----
-Process substitution connects the output of a command to a file. This enables a command to accept the output of multiple commands.
-Useful with diff for example:
-
-```bash
-diff <(ls dirA) <(ls dirB)
-```
-
-> Important! Don't but the <() inside quotes.. it will report: cannot find file \ No newline at end of file
diff --git a/Bash.md b/Bash.md
new file mode 100644
index 0000000..239ac40
--- /dev/null
+++ b/Bash.md
@@ -0,0 +1,6 @@
+---
+tags:
+ - bash
+---
+A scripting language in which a user can string together [[Shell]] commands in a reusable file called a script. The script can be executed (or "called") and it will execute the string of commands.
+They are not full general purpose programming languages, even though they often have similar constructs available. \ No newline at end of file
diff --git a/Building a command-line using arrays.md b/Building a command-line using arrays.md
new file mode 100644
index 0000000..8e187c7
--- /dev/null
+++ b/Building a command-line using arrays.md
@@ -0,0 +1,34 @@
+---
+tags:
+ - bash
+---
+[[Bash]] [[Globbing patterns]]
+
+---
+See https://www.shellcheck.net/wiki/SC2086
+
+issue with building a command-line and prevent globbing by quoting parameter expansion, solution: use array.
+
+```
+#!/usr/bin/env bash
+function test() {
+ echo "${@}"
+}
+function blaat() {
+ local flags
+ test hello "${flags[@]}"
+}
+function blaat1() {
+ local flags
+ flags=(a b c)
+ test hello "${flags[@]}"
+}
+blaat
+blaat1
+```
+
+```
+❯ bash /tmp/tmp.qI8lPlBQUe
+hello
+hello a b c
+``` \ No newline at end of file
diff --git a/Globbing patterns.md b/Globbing patterns.md
index 12b7582..bc7534c 100644
--- a/Globbing patterns.md
+++ b/Globbing patterns.md
@@ -2,6 +2,9 @@
tags:
- linux
---
+[[Bash]]
+
+---
https://linux.die.net/man/7/glob
**Wildcards**
diff --git a/Heredoc.md b/Heredoc.md
new file mode 100644
index 0000000..84c0fa5
--- /dev/null
+++ b/Heredoc.md
@@ -0,0 +1,23 @@
+---
+tags:
+ - bash
+---
+[[Bash]]
+
+---
+```
+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
diff --git a/Nova compute evacuation.md b/Nova compute evacuation.md
new file mode 100644
index 0000000..409ea42
--- /dev/null
+++ b/Nova compute evacuation.md
@@ -0,0 +1,10 @@
+---
+tags:
+ - openstack
+---
+To evacuate a compute node we can `nova host-evacuate <hostname>`. I did it like this on the access node:
+```
+nova --os-token gAAAAABoLXVPU1N-pYc8Xm7ypmWZX_hSuy7psMS_kudoYg6msHZdXYk_dordZB8Imm6-PT8916iPH5n9BvYLmHAQl7UGHuSNsfHZH8k_s1EPbfU8aE15s8Hu0ngNLW2amv_C-peJ8BZLHIl3K7cz2b05D0wRDnzbWl0h0w5NyY6aY_8YcMkVIzc --os-project-name hostnet --os-auth-url https://keystone.os1.openstack.group.one:5000/v3 host-evacuate n28.compute.env.vps1-cph8.one.com
+```
+
+[This](https://www.danplanet.com/blog/2016/03/03/evacuate-in-nova-one-command-to-confuse-us-all/) webpage has some useful information on evacuation in its different forms. \ No newline at end of file
diff --git a/Null substitution.md b/Null substitution.md
new file mode 100644
index 0000000..276a2e6
--- /dev/null
+++ b/Null substitution.md
@@ -0,0 +1,25 @@
+---
+tags:
+ - bash
+---
+[[Bash]] [[Process substition (tmp file)]] [[Parameter subsitution]]
+
+---
+[This](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02) page contains a table with [[Parameter subsitution]]
+
+When we want to expand a variable into an argument to a command but the variable is empty it will expand to **an empty string**. This is often unwanted, we just want `null` which is removed from the command-line.
+
+*Example*
+```
+openstack server delete server "${waitFlag}"
+```
+if `waitFlag` is empty this will become:
+```
+openstack server delete server ''
+```
+which results in an error.
+
+This is where we can use `null substitution`:
+```
+openstack server delete server "${waitFlag:+$waitFlag}"
+``` \ No newline at end of file
diff --git a/Parameter subsitution.md b/Parameter subsitution.md
new file mode 100644
index 0000000..c50f231
--- /dev/null
+++ b/Parameter subsitution.md
@@ -0,0 +1,8 @@
+---
+tags:
+ - bash
+---
+[[Bash]] [[Null substitution]] [[Process substition (tmp file)]]
+
+---
+[This](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02) page contains a useful table. \ No newline at end of file
diff --git a/Process substition (tmp file).md b/Process substition (tmp file).md
new file mode 100644
index 0000000..c9103c2
--- /dev/null
+++ b/Process substition (tmp file).md
@@ -0,0 +1,15 @@
+---
+tags:
+ - bash
+ - howto
+---
+[[Bash]] [[Parameter subsitution]] [[Null substitution]]
+
+Process substitution connects the output of a command to a file. This enables another command to accept the output of multiple commands as files if it expects files.
+
+An example of this is `diff`, which outputs the difference between two files:
+```bash
+diff <(ls dirA) <(ls dirB)
+```
+
+> Important! Don't but the <() inside quotes.. it will report: cannot find file \ No newline at end of file
diff --git a/Setting traps.md b/Setting traps.md
new file mode 100644
index 0000000..cd36e80
--- /dev/null
+++ b/Setting traps.md
@@ -0,0 +1,10 @@
+---
+tags:
+ - bash
+---
+With traps you can configure a function that is run upon a specific signal or when the script fails or exits normally.
+
+`trap fn ERR` > when an error occurrs
+`trap fn EXIT` > any exit, also errors and interrupts
+`trap fn SIGINT` > when interrupted
+`trap fn ERR SIGINT` > either an interrupt or error occurred \ No newline at end of file
diff --git a/Shell.md b/Shell.md
new file mode 100644
index 0000000..ed90df2
--- /dev/null
+++ b/Shell.md
@@ -0,0 +1,5 @@
+---
+tags:
+ - linux
+---
+A shell is a command-line interface; it interprets textual instructions (commands) to the operating system. \ No newline at end of file
diff --git a/daily/20-May-2025.md b/daily/20-May-2025.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/daily/20-May-2025.md
diff --git a/daily/27-May-2025.md b/daily/27-May-2025.md
new file mode 100644
index 0000000..908736b
--- /dev/null
+++ b/daily/27-May-2025.md
@@ -0,0 +1,4 @@
+Decided that devenv is too invasive for use at work; I can't commit its .envrc nor .pre-commit-config.yaml. Therefore I'm setting up just regular shell.nix usage. I quickly ran into an issue where the nix shell is using bash and found a tool called Lorri which promises to be useful for developer environments with shell.nix. Let's hope that is less invasive than devenv.
+Thus far it's not very nice, it install stuff on the background ( a systemd daemon that listens for change ) of which you have no idea when its done.
+
+TIL: gitlab ci job can specify `resource_group` to make it mutually exclusive with other jobs that have this resource group. \ No newline at end of file