I hope, you're familiar with parameter scopes, i.e. local and global variables. Global variables are visible in all contexts including subshells, functions and what not. Local variables are only visible in the current scope (e.g. a function).
Today I want to show you some examples of parameter expansion or parameter substitution as it is called in Bash. I've already used parameter expansion a few times in this series but now I want to show you how it works (at least some basics, I don't want to report the whole manual here).
Have you ever wondered why ZSH provides so many features but is still so fast? That's because of its autoloading mechanism. Functions can be marked as empty so they aren't loaded before they are executed the first time. This saves a lot of memory and much processing power.
Yesterday I told you about the chpwd() hook function. Today I want to go one step further and round up this topic. As you might have found out (or maybe you knew it already or at least guessed it), there are also other hook functions and today I want to present you some.
There is a number of magic functions called hook functions in ZSH which are automatically executed under certain circumstances. One of these functions is chpwd() and it is executed each time you change the current working directory.
Today I'm showing you how to edit variables by using vared. The vared shell builtin invokes the ZSH line editor, to interactively edit variables. This is sometimes very useful when you have appended values to a variable but then recognize that you added something you didn't want to add. Instead of rebuilding all the contents of the variable you could just use vared and clean up the mess.
One unique feature in ZSH is that you can redirect streams to multiple outputs or inputs simultaneously. With this multi-stream redirection you can, e.g., redirect STDOUT OR STDERR of a program to more than one file at the same time without using a command line tool such as tee.
By default, the ZSH auto completion is very rough. This seems very weird when you think of how powerful ZSH's expansion system is where you can expand any expression with the TAB key. But when you hit TAB to complete something, the only thing you can do is to toggle through a very basic list of files or commands.
But in fact, the ZSH completion system is very powerful. And when I say that, I mean very powerful. ZSH has a completely programmable completion system. For a long time, this has been a killer feature of ZSH. It still is, but other shells such as Bash have now implemented this as well. But in some areas, the ZSH completion system might still be the better one.