O'Reilly logo

Learning Shell Scripting with Zsh by Gastón Festari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Function definitions

Finally, we will turn our attention to compsys, zsh's completion system. This is one of the most complex parts of the shell for users and developers alike. Before we dive into compsys, however, we need to make a quick stop and meet an actual function in the wild.

Tip

As usual, you can learn more about compsys via the manpages. Of particular interest are man zshcompsys and man zshcompwid.

Here's what one of these looks like:

hi() {
print 'Hello, world'
}

Here, we have defined the hi function, which is how we'll call it again later when we need it. This will, in turn, print Hello, world every time we use it. So let's get to it, shall we?

Open your terminal emulator of choice, and type the following (one line at a time):

% hi() {

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required