Last active
September 21, 2021 11:53
-
-
Save andras-tim/f8aebf9243cecf3719d27d020a718ef8 to your computer and use it in GitHub Desktop.
I love pipes, redirects and named fds... in ZSH!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/zsh | |
set -e | |
# TAB indented file! | |
### PREPARATION ### | |
# mkdir test | |
# cd test | |
# wget -q https://gist.github.com/andras-tim/f8aebf9243cecf3719d27d020a718ef8/raw/fun.zsh -O - | zsh | |
### MAGIC CODE ### | |
# Challenge: Let's explain this section in a comment! ;) | |
echo 2 >a | |
exec {b}< <(echo 3) | |
echo 1 | cat - <a <&${b} <<-EOF <<<5 2>&1 >c >|d >>e | |
4 | |
EOF | |
### (: WTF :) ### | |
cat c # == cat d == cat e | |
#1 | |
#2 | |
#3 | |
#4 | |
#5 | |
ls | |
# a c d e | |
### CLEANUP ### | |
rm a c d e | |
exec {b}>&- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you run this script in
bash
, the magiccat
will get the last input and the last output redirection only... 😜