Skip to content

Commit 4229d78

Browse files
authored
heredocs herestring fix (#48)
1 parent 1baa29c commit 4229d78

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ebook/en/content/023-bash-redirection.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,13 @@ COMMAND << EOF
182182
...
183183
EOF
184184
```
185-
186-
Note here that `EOF` represents the delimiter (end of file) of the heredoc. In fact, we use any alphanumeric word in it's place to signify the start and end of the file. For instance, this is a valid heredoc:
185+
Note here that `EOF` represents the delimiter (end of file) of the heredoc. In fact, we can use any alphanumeric word in it's place to signify the start and the end of the file. For instance, this is a valid heredoc:
187186
```
188187
cat << randomword1
189188
This script will print these lines on the terminal.
190-
Note that cat only accepts a filename as it's argument. Using this heredoc,
191-
we can create a temporary file with these lines as it's content and pass
192-
that file as the argument to cat.
189+
Note that cat can read from standard input. Using this heredoc, we can
190+
create a temporary file with these lines as it's content and pipe that
191+
into cat.
193192
randomword1
194193
```
195194

@@ -199,22 +198,24 @@ Further, we can attach more pipes as shown:
199198
```
200199
cat << randomword1 | wc
201200
This script will print these lines on the terminal.
202-
Note that cat only accepts a filename as it's argument. Using this heredoc,
203-
we can create a temporary file with these lines as it's content and pass
204-
that file as the argument to cat.
201+
Note that cat can read from standard input. Using this heredoc, we can
202+
create a temporary file with these lines as it's content and pipe that
203+
into cat.
205204
randomword1
206205
```
207206

208-
Also, pre-defined variables can be used inside the documents.
207+
Also, pre-defined variables can be used inside the heredocs.
209208

210209
# HereString
211210

212211
Herestrings are quite similar to heredocs but use `<<<`. These are used for single line strings that have to be piped into some program. This looks cleaner that heredocs as we don't have to specify the delimiter.
213212

214213
```
215-
cat <<<"this is an easy way of passing strings to the stdin of a program (here wc)" | wc
214+
wc <<<"this is an easy way of passing strings to the stdin of a program (here wc)"
216215
```
217216

217+
Just like heredocs, herestrings can contain variables.
218+
218219
## Summary
219220
|**Operator** |**Description** |
220221
|:---|:---|

0 commit comments

Comments
 (0)