You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ebook/en/content/023-bash-redirection.md
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -182,14 +182,13 @@ COMMAND << EOF
182
182
...
183
183
EOF
184
184
```
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:
187
186
```
188
187
cat << randomword1
189
188
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.
193
192
randomword1
194
193
```
195
194
@@ -199,22 +198,24 @@ Further, we can attach more pipes as shown:
199
198
```
200
199
cat << randomword1 | wc
201
200
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.
205
204
randomword1
206
205
```
207
206
208
-
Also, pre-defined variables can be used inside the documents.
207
+
Also, pre-defined variables can be used inside the heredocs.
209
208
210
209
# HereString
211
210
212
211
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.
213
212
214
213
```
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)"
216
215
```
217
216
217
+
Just like heredocs, herestrings can contain variables.
0 commit comments