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

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…

Contents