O'Reilly logo

Linux and Unix Shell Programming by David Tansley

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

19.6. Using functions in the shell

When you have collected a few functions that you use regularly you can put them in a function file and load the file into the shell. This method is called sourcing a file or using the dot command.

The file should contain the #!/bin/sh at the top of the file. The file can be called anything you like, but be sure to call it something meaningful to its task, for example ‘ functions.main ’.

Once the file is loaded into the shell, you can call the functions from the command line or your script. To see all your defined functions use the set command. The output will contain all the functions that have been loaded into the shell.

To make changes to any of your functions first use the unset command to delete the function ...

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