Getting started
Using trap to react to signals and system events
Listing files
Aliasing
Jobs and processes
Redirection
Control structures
Using cat
Arrays
Functions
Bash Parameter Expansion
Sourcing
Find
Here documents and here strings
Here documents and here strings
Execute command with here document
Indenting here documents
Here strings
Create a file
Run several commands with sudo
Limit Strings
Quoting
Conditional Expressions
Scripting with parameters
History substitutions
Math
Scoping
Process substitution
Programmable completion
Customizing PS1
Brace Expansion
Bash Arithmetic
getopts smart positional-parameter parsing
Debugging
Pitfalls
Script shebang
Pattern matching and regular expressions
Keyboard shortcuts
Change shell
Copying with cp
Internal variables
Job control
Case statement
Word splitting
Read a file
File transfer with scp
Pipelines
Managing PATH environment variable
Avoiding date using printf
Chain of commands and operations
Type of shells
true, false and commands
Color script output cross-platform
Navigating directories
Using sort
Namespace
co-processes
Typing variables
Jobs at specific types
Associative arrays
Handling the system prompt
Creating directories
File execution sequence
The cut command
Bash on Windows 10
Cut command
Splitting files
Global and local variables
Design Patterns
CGI Scripts
Select keyword
When to use eval
Networking with bash
Parallel
Grep
Strace
Sleep
Decodi
Contributors

Limit Strings

suggest change

A heredoc uses the limitstring to determine when to stop consuming input. The terminating limitstring must

Correct:

cat <<limitstring
line 1
line 2
limitstring

This will output:

``` line 1 line 2
Incorrect use:

cat <<limitstring line 1 line 2 limitstring

Since `limitstring` on the last line is not exactly at the start of the line, the shell will continue to wait for further input, until it sees a line that starts with `limitstring` and doesnt contain anything else. Only then it will stop waiting for input, and proceed to pass the here-document to the `cat` command.

Note that when you prefix the initial limitstring with a hyphen, any tabs at the start of the line are removed before parsing, so the data and the limit string can be indented with tabs (for ease of reading in shell scripts).

cat <<-limitstring line 1 has a tab each before the words line and has line 2 has two leading tabs limitstring

will produce

> ```
line 1    has a tab each before the words line and has
line 2 has two leading tabs

with the leading tabs (but not the internal tabs) removed.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents