Skip to Content
Linux Command Line and Shell Scripting Bible, 4th Edition
book

Linux Command Line and Shell Scripting Bible, 4th Edition

by Richard Blum, Christine Bresnahan
January 2021
Intermediate to advanced content levelIntermediate to advanced
832 pages
18h 3m
English
Wiley
Content preview from Linux Command Line and Shell Scripting Bible, 4th Edition

CHAPTER 11Basic Script Building

Now that we've covered the basics of the Linux system and the command line, it's time to start coding. This chapter discusses the basics of writing shell scripts. You'll need to know these basic concepts before you can start writing your own shell script masterpieces.

Using Multiple Commands

So far you've seen how to use the command-line interface (CLI) prompt of the shell to enter commands and view the command results. The key to shell scripts is the ability to enter multiple commands and process the results from each command, even possibly passing the results of one command to another. The shell allows you to chain commands together into a single step.

If you want to run two commands together, you can enter them on the same prompt line, separated with a semicolon:

$ date ; who
Mon Jun 01 15:36:09 EST 2020
Christine tty2        2020-06-01 15:26
Samantha tty3         2020-06-01 15:26
Timothy  tty1         2020-06-01 15:26
user     tty7         2020-06-01 14:03 (:0)
user     pts/0        2020-06-01 15:21 (:0.0)
 
$

Congratulations, you just wrote a shell script! This simple script uses just two Bash shell commands. The date command runs first, displaying the current date and time, followed by the output of the who command, showing who is currently logged on to the system. Using this technique, you can string together ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Command Line and Shell Scripting Bible, 3rd Edition

Linux Command Line and Shell Scripting Bible, 3rd Edition

Christine Bresnahan, Richard Blum

Publisher Resources

ISBN: 9781119700913Purchase Link