| Lesson 2 || A shell script as a macro |
| Objective || Similarities between shell script/ entering commands |
Shell Script as a Macro in Unix
Explain the similarities between a shell script and entering commands.
You can better understand how shell scripts are used by thinking of a shell script as a set of commands that could be executed at a command line, but which have been automated in a script.
Comparing shell scripts to macros
Another way to think of this is that a shell script is like a macro for work you do in a shell. Macros
are programs that record
keystrokes and add additional control elements to do a task that otherwise would be done interactively (with a person entering each command and responding to the results).
Suppose, for example, that you had a collection of hundreds of word processor documents, and each document needed to have a certain set of words updated using the search and replace command. To complete this task in each document would be tedious and time consuming. By creating a macro in your word processor, you could automate the steps of the task.
In a similar way, a shell script automates commands that would normally be executed at a UNIX command line, but which are repetitive and thus can be automated. For example, loading certain files each time the system starts could be done by hand, entering each command name. A shell script can automate this process.
In addition to the commands that you would otherwise execute manually, a shell script contains control information that determines which commands to skip in certain situations, how many times to execute a command,
and other details affecting the way the script works. The remaining lessons in this module describe these control components of a shell script.
The following SlideShow shows a series of commands being executed. This is the type of task that is well-suited to being performed by a shell script.
Shell Script Macro
Windows 10 - bash for Windows
In August 2016, Microsoft released bash for the Windows 10 Anniversary release, so if you’re working in Windows you can still run a bash shell. It is easy to install bash for Windows 10, but this course assumes you are running on a Unix-like operating system such as OS X or Linux.
Feel free to test these scripts on Windows 10. The beauty of bash is portability, and many scripts on this website work as is.
Using the terminal to interact with your system may seem like a daunting task. Over time, though, it becomes more natural to just open a terminal to make a quick system change than to move your mouse around in menu after menu, trying to find the options you want to change.
The next lesson describes using external and built-in commands within a shell.
: Lists of commands within a program such as a word processor that are normally executed by a user, but which have been stored or recorded, and can thus be executed by the program without user intervention.