The Components of a Shell Script
#!/bin/bash
#A simple script that displays the current date and time
echo "The current date and time is:"
date
exit 0
#!/bin/bash
The first line of any shell script should specify which shell the script is written to run under. In this case, the /bin/bash shell is specified. When a script is run, a subshell will be created using the shell specified here and the script contents will be
processed within it.
#
A simple script that. . . .
This part of the script is a comment that describes what the script does. Notice that this part of the script begins with a # character to indicate that
the text that comes after it is a comment. Because it is a comment, this part of the script is not displayed on the screen when it is run. Comments are optional. The script will run just fine without them. However, it’s considered good form to include a comment at the beginning of your scripts right after the shell declaration that describes what the script does and, optionally, who wrote it.
echo, date
These elements in the script are simple commands that are typically used at the shell prompt. The echo command is used to display text on the screen. The date command is used to display the current date and time on the screen.
exit 0
This part of the script is its end. It tells the shell what to do after it is done running the commands in the script. In this case, it tells the shell to exit the script.
LX0-104 Exam Objectives (F)
No comments:
Post a Comment