From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Here documents - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Here documents
- [Instructor] Here documents are handy sometimes. You may well run into 'em when you're looking at other people's scripts, but let's take a quick look. A here document's essentially a way to embed a bunch of input inside of a script that's easier to work with. And they can avoid having to create a new file just to hold some lines of text, for example. The way here documents work is you do a << and then a string that's not part of the input you're trying to work with, and then you have that string to mark where the end of the input is. So in this case, we would sort these four lines, cherry, banana, apple, orange. So sort is taking its input right here from the file. It's essentially redirecting standard input to be the contents that immediately follows it, instead of redirecting standard input, say, from a separate file. This could be handy. If you do <<- and then the string, you could put a tab in front of the lines of input. That makes it a little more readable. It turns out that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
The typeset and declare commands for variables and arrays5m 59s
-
(Locked)
Looping with while sequences and reading input6m 12s
-
(Locked)
Looping with for, the seq command, and backticks8m 3s
-
(Locked)
Defining functions and using return and exit4m 17s
-
(Locked)
Using file descriptors, file redirection, and pipes7m 23s
-
(Locked)
Here documents3m 54s
-
(Locked)
Open and close file descriptors5m 22s
-
(Locked)
Control-flow if-then-else with the test command4m 42s
-
(Locked)
Case statements3m 45s
-
(Locked)
Using arithmetic operators3m 26s
-
(Locked)
Challenge: Variables in functions, loops, and arithmetic2m 46s
-
(Locked)
Solution: Variables in functions, loops, and arithmetic2m 42s
-
-
-
-