Skip to content

Commit 93d0654

Browse files
pismyrstacruz
andauthored
Bash: add Herestring & Process substitution chapters (#2184)
This PR adds: - link to the Heredoc refdoc (always handy for not straightforward concepts) - chapter about Herestring - chapter about Process Substitution (I know it is already tackled in the _Redirection_ chapter but I believe it deserves its own one... Congrats for this cheatsheet, by far my most beloved one ever !! --------- Co-authored-by: Rico Sta. Cruz <[email protected]>
1 parent 17bd2c9 commit 93d0654

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

bash.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,30 @@ hello world
791791
END
792792
```
793793

794+
Heredoc allows a section of your source code to be treated as a file. See [Bash Reference Manual](https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Here-Documents).
795+
796+
### Herestring
797+
798+
```sh
799+
tr '[:lower:]' '[:upper:]' <<< "Will be uppercased, even $variable"
800+
```
801+
802+
Herestring allows a string to be treated as a standard input (stdin). See [Bash Reference Manual](https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Here-Strings).
803+
804+
### Process substitution
805+
806+
```sh
807+
# loop on myfunc output lines
808+
while read -r line; do
809+
echo "$line"
810+
done < <(myfunc)
811+
812+
# compare content of two folders
813+
diff <(ls "$dir1") <(ls "$dir2")
814+
```
815+
816+
Process substitution allows the input (or output) of a command to be treated as a file. See [Bash Reference Manual](https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html).
817+
794818
### Reading input
795819

796820
```bash

0 commit comments

Comments
 (0)