Shell & Bash
Shell debugging
The .zshrc provides a debugging variable which uses zprof to log the load times when specified.
To use it, set:
Bash scripting
Heredocs
The << is a here-document (NOT SUPPORED IN FISH! see here)
here-documents feed a command list to STDIN (hence why it wont work with echo, which doesnt read from stdin!)
e.g. count lines with wc -l is a simple example to demonstrate using heredoc to feed 4 lines to stdin to wc and print line count
Herestring
The <<< is a here string.
Similarly to heredoc, it goes AFTER the command.
It seems pretty similar to piping input with echo, but i found with my bw-view and bw-edit functions that echo prints newlines!. Thus will break jq parsers
A simple demonstration below, we can see a multilint string is printed across multi lines (as expected) with echo, whereas with <<< it pipes directly in
Another addition to using
grep |is id does not create another process
Unlike heredoc, it only takes a stringle string and does NOT require a delimeter
Color pipes
I've noticed that alot of linux utilities will not print colour if they thing they are being sent to a TTY terminal they don't print colour.
E.g. with eza need to add this and then colours will appear to force it
I guess the rationale is if the user is piping to another program, escape codes will show up as garbage in a text file for example
Another great example when trawling through syslogs is dmesg (seems that --color=always is a standardish unix option)
Options
getopts is usedful, i (think) its just fancy iterator through bash $@ args?
e.g. checking a -x flag
e.g. multi args (yes im too lazy to do it over multi line in while to make it clearer)
Shell scripting
jq
To start with, jq has the "identity" operator ., where jq '.' is equivalent to jq.
And by default it reads from stdin. Can see this just by running it
That's me typing the inputs and
jqechoing it back to me (formatted)
Or, can extract value of key "a" from user stdin:
which brings us neatly along to the merge operator, *, to combine objects together.
can see here it will take my stdin object and merge with {a:1}
this is NOT to be confused with the mathematical multiplication operator lmao
now the -s operator will join things together, so if i enter a few lines here to STDIN (then press ctrl-d to prompt end ofstdin) it will produce an array, rather than processing 1 by 1.
another great example of heredoc! to pipe some lines of stdin to jq and see it process them (all as one!) so don't need to fanny around with multiple commands an ctrl-d
and now using the full syntax of jq with
can see it here
without the
-sits just processingtest1andtest2as 2 separate commands...?

