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
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]>
Copy file name to clipboardExpand all lines: bash.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -791,6 +791,30 @@ hello world
791
791
END
792
792
```
793
793
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
+
whileread -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).
0 commit comments