Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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

Shell Line Input

In the previous chapters, we learned how to process files line by line using predefined commands such as cut or tr. However, we are often limited by the fact that one command can do only one operation at a time. The shell provides some facilities to allow processing a file or typed input line by line. Some of these are discussed in the following section.

Line Input Commands

These commands allow us to write scripts that work with input data line by line and process it.

The read Command

The shell provides the read command to process input in a line-by-line fashion. This command has two main uses:

  • To read input from the user interactively from scripts
  • To read input from a file and process it

The read command accepts any number of variable names as arguments. When executed, it attempts to read text from its stdin and assign the input to the variables. For example, look at the following snippet:

robin ~ $ read COLOR THING
red apple
robin...
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 $19.99/month. Cancel anytime
Banner background image