Consider the following zsh script:
echo $(echo "yes") Now, echo takes a string and turns it into standard output. On the other hand, the $(X) notation evaluates X and turns its standard output into a string.
Expectedly, the standard output is as follows:
dteiml@DominiksMBP2019 ~ echo $(echo "yes") yes So far so good.
Now consider the following script involving bat. bat is a pretty-prettier for cat, kind of like Pygments.
echo "yes" | bat The standard output is as follows:
dteiml@DominiksMBP2019 ~ echo "yes" | bat ───────┬───────────────────────────────── │ STDIN ───────┼───────────────────────────────── 1 │ yes ───────┴───────────────────────────────── So I would expect the following command:
echo $(echo "yes" | bat) to produce the same output (pretty-formatted). However, it just outputs "yes":
dteiml@DominiksMBP2019 ~ echo $(echo "yes" | bat) yes Based on the above, this is unexpected. Does it use some zsh api that would allow it to determine if it's being executed inside a $(X) block, or something else?
PS I don't really need this for anything, just trying to get a better understanding of bash/zsh.
Thanks in advance!
batis checking whether its output is a TTY and declining to reformat for human-targeted output when the output is a FIFO instead of a TTY. This isn't a bash/zsh choice, it's a bat choice.isatty(1)is true), you'd have some serious bugs unless you changed your code toecho "$(echo "yes" | bat)"with the quotes.ls --color=autoonly writes color-formatting when going straight to a terminal, not when writing to a pipe).batperforms this check, see github.com/sharkdp/bat/blob/…, using a variable populated at github.com/sharkdp/bat/blob/… --atty::is(Stream::Stdout)