Quantcast
Channel: Which shells support ANSI-C quoting? e.g. $'string' - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

Which shells support ANSI-C quoting? e.g. $'string'

$
0
0

I have a shell script that uses the following to print a green checkmark in its output:

col_green="\e[32;01m"col_reset="\e[39;49;00m"echo -e "Done ${col_green}✓${col_reset}"

After reading about Bash's ANSI-C Quoting, I realized I could use it when setting my color variables and remove the -e flag from my echo.

col_green=$'\e[32;01m'col_reset=$'\e[39;49;00m'echo "Done ${col_green}✓${col_reset}"

This seems appealing, since it means the message prints correctly whether it's passed to Bash's builtin echo or the external util /bin/echo (I'm on macOS).

But does this make the script less portable? I know Bash and Zsh support this style of quoting, but I'm not sure about others.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>