Book Image

Command Line Fundamentals

By : Vivek Nagarajan
Book Image

Command Line Fundamentals

By: Vivek Nagarajan

Overview of this book

The most basic interface to a computer—the command line—remains the most flexible and powerful way of processing data and performing and automating various day-to-day tasks. Command Line Fundamentals begins by exploring the basics, and then focuses on the most common tool, the Bash shell (which is standard on all Linux and iOS systems). As you make your way through the book, you'll explore the traditional Unix command-line programs as implemented by the GNU project. You'll also learn to use redirection and pipelines to assemble these programs to solve complex problems. By the end of this book, you'll have explored the basics of shell scripting, allowing you to easily and quickly automate tasks.
Table of Contents (6 chapters)

Conditionals and Loops

As with any other general-purpose programming language, the shell provides conditional and looping constructs. They are especially useful within shell scripts. We will learn some of the commonly used conditionals and loops in further sections.

Note

Conditionals and loops (along with functions, which we will cover later) make the shell language Turing complete. This is a computer science notion that means that it is equivalent to any general programming language in terms of its capabilities.

Conditional Expressions

As we saw in the previous chapter, every command returns an exit code that is interpreted as true and false for zero and non-zero values, respectively. A conditional expression is any shell command evaluating to true or false. One mechanism that augments this is the [[ ]] construct, which provides a way to test for a condition and return a Boolean. This syntax is as follows:

[[ EXPRESSION ]]

Here, EXPRESSION has a syntax similar to...