This chapter shows how to create and call subroutines in a script.
The topics covered in this chapter are as follows:
In the previous chapters we have seen mostly simple scripts that were not very complicated. Scripts can actually do a whole lot more which we are about to see.
First, let's start with a selection of simple but powerful scripts. These are mainly shown to give the reader an idea of just what can be done quickly with a script.
The tput clear
terminal command can be used to clear the current command-line session. You could type tput clear
all the time, but wouldn't just cls
be nicer?
Here's a simple script that clears the current screen:
#!/bin/sh # # 5/8/2017 # tput clear
Notice that this was so simple I didn't even bother to include a Usage
message or return code. Remember, to make this a command on your system do this:
cd $HOME/bin
cls
chmod 755 cls
You can now type cls
from any terminal (under that user) and your screen will clear. Try it.