Skip to content

Instantly share code, notes, and snippets.

@andras-tim
Last active September 21, 2021 11:53
Show Gist options
  • Save andras-tim/f8aebf9243cecf3719d27d020a718ef8 to your computer and use it in GitHub Desktop.
Save andras-tim/f8aebf9243cecf3719d27d020a718ef8 to your computer and use it in GitHub Desktop.
I love pipes, redirects and named fds... in ZSH!
#!/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}>&-
@andras-tim
Copy link
Author

If you run this script in bash, the magic cat will get the last input and the last output redirection only... 😜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment