I'm trying to write a zsh script which can echo some useful information with colours. As a test I made the following file:
#!/bin/zsh
echo $fg[red] "test"
which should just output test in red, however when I run it it outputs test but it is in the default text colour rather then red.
If I just type echo $fg[red] "test" directly into my terminal, then it works correctly and I see the red test, but when I run my file with the above code, the colours don't work.
Is there something I'm missing or doing wrong?
You need to load colors first that is shipped with zsh (/usr/share/zsh/functions/Misc/colors for me) and initialized all the $fg, $bg and more variables
#!/bin/zsh
autoload colors && colors
echo $fg[red] "test"
will print a red test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With