Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Command Line Fundamentals

You're reading from   Command Line Fundamentals Learn to use the Unix command-line tools and Bash shell scripting

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher
ISBN-13 9781789807769
Length 314 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Vivek Nagarajan Vivek Nagarajan
Author Profile Icon Vivek Nagarajan
Vivek Nagarajan
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime