| created on | January 18, 2022 |
A 2nd order reference is a reference that references the variable with the name which is the value in the referencing variable. I.e.:
The value of the 2nd variable (food) is the name of the 1st variable (fruit). Dereferencing the value of the 1 variable is done by preceding the second variable with an exlamation mark .
You can also dereference a 2nd order variable with :
So, one might ask, what’s that good for?
Given a numer of variables that hold commands to set the terminal foreground colors and a command to reset the terminal foreground color back to normal:
and a function ’logformat’ that dereferences the command to set the terminal color from the first function parameter, so that ’logformat’ can be used like
The function ’logformat’, which takes the color of the log label as an parameter, can be written as
or with an additional parameter for the label and some some code to clear the current line:
Now we can write log functions that print out the log message with a colored label:
Now we can log with some nice colors:
shell code for log functions with colored loglevel markers log.lib