[go: up one dir, main page]

Today I Learned

tags


2021/09/15

That you can, technically, write inline comments in bash. Specifically, you have to put the comments in a subshell:

echo abc `#put your comment here` \
     def `#another chance for a comment` \
     xyz etc

^ from https://stackoverflow.com/a/23872003/6571327


2021/10/04

that different versions of sort(1) have different sorting presets. For example, on ubuntu 20.04 vs debian buster, sort will swap the order of how it sorts _s. These differences can be resolved by passing --unique --dictionary-order --stable.

Bonus: -h/--human-numeric-sort can sort SI suffixes.


2021/10/12

about the shell until keyword, which is equivalent to while !.


2021/10/28

That you can detect the terminal you’re running in (including vscode) by checking the value of "${TERM_PROGRAM:-}". The VS Code integrated termial always has a $TERM_PROGRAM of vscode.

Source: https://stackoverflow.com/a/59231654/6571327


2022/04/11

You can use journalctl -u ${service_name}.service --since ${time:-today} to view the logs of a systemd service: https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs


2022/05/10

That you can call time(1) to time how long a shell command takes, like so:

; time terraform fmt -write=true -recursive .
# terraform fmt -write=true -recursive . 0.10s user 0.23s system 24% cpu 1.377 total

2022/07/02

That you can unescape newlines with printf "%b" 'escaped\nstring':

escaped='a\nb'
printf "%b" "$escaped"
# a
# b

2022/07/29

that in bash and zsh, you can put a newline in a variable like so:

newline=$'\n'
echo ">>>${newline}<<<"

learned from: https://stackoverflow.com/a/4456399/6571327


2022/08/24

that you can lsblk to list the block devices that the OS knows about without sudo.

that you can sudo growpart to increase a partition size without restarting the machine.


2022/08/29

That you can list the listening ports on a UNIX machine using sudo lsof -i -P -n | grep LISTEN


2022/10/03

That you can write >& 1 and it still redirects to stdout! example:

f() { echo "ok" >&2; }
f 2>& 1 | grep ok

2022/10/11

That terraform plan -detailed-exitcode exists: 0 means no diff, 1 means error, 2 means a diff exists.

Also, that you can print the source code of a bash function like so:

print_fn_src() { declare -f "$1"; }

2022/10/18

That BSD arch command found on Macs also supports a -${arch} flag for running universal binaries.


2022/10/23

That ARIA stands for Accessible Rich Internet Applications! See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA


That in linux ls(1) uses the environment variable LS_COLORS to determine the colors in which the filenames are to be displayed. Also, that linux specifies a dir_colors(5) configuration file format for dircolors(1), which exports LS_COLORS

See https://man7.org/linux/man-pages/man5/dir_colors.5.html


That nix is complicated, which is exactly what my prior research told me.

On one hand, it is AWESOME to cd into a project and watch direnv automatically spawn a development shell with all the fixings. On the other, the nix ecosystem is bewildering. I read through a few articles:

Then there are the reasonable-yet-still-more confusing tools like

both of which expose tools to use nix (package manager) to provide development environments without requiring devs to write any nix (the language). Since I’m still struggling with the configuration language, I’m sympathetic to anyone wanting to avoid writing nix.

By dint of procrastinating, I now know that

I’m still putting off reading up on nix overlays at the time of writing.

I could see someone writing SDKs for nix-the-package-manager in non-nix languages that serialize and deserialize to JSON, just like is happening to infrastructure-as-code languages (pulumi, helm, terraform cloud development kit), etc.


that you can search for nix package names on https://search.nixos.org/packages


2022/10/24

That you can list all addresses in terraform state by running

terraform state list

Docs at https://developer.hashicorp.com/terraform/cli/commands/state/list


Also, that compgen -v is a function, at least on Mac zsh. Apparently in zsh compgen -v calls something like

for var_name in "${(k)parameters[@]}"; do
  printf '%s\n' "$var_name"
done

which is the first time I’ve seen that kind of shell syntax. It generates a bad substitution message in bash 3.2, so I can only assume it’s zsh-specific.


2023/05/30

That there’s a Linux command to do sql-like JOINs of lines in files, possibly based on a field in each line: join(1)