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

Answer by Gilles 'SO- stop being evil' for Which shells support ANSI-C quoting? e.g. $'string'

$
0
0

$'…' is a ksh93 feature that is also present in zsh, bash, mksh, FreeBSD sh and in some builds of BusyBox sh (BusyBox ash built with ENABLE_ASH_BASH_COMPAT). It isn't present in the POSIX sh language yet. Common Bourne-like shells that don't have it include dash (which is /bin/sh by default on Ubuntu among others), ksh88, the Bourne shell, NetBSD sh, yash, derivatives of pdksh other than mksh and some builds of BusyBox.

A portable way to get backslash-letter and backslash-octal parsed as control characters is to use printf. It's present on all POSIX-compliant systems.

esc=$(printf '\033') # assuming an ASCII (as opposed to EBCDIC) systemcol_green="${esc}[32;01m"

Note that \e is not portable. It's supported by many implementations of printf but not by the one in dash¹. Use the octal code instead.

¹ It is supported in Debian and derivatives that ship at least 0.5.8-2.4, e.g. since Debian stretch and Ubuntu 17.04.


Viewing all articles
Browse latest Browse all 6

Trending Articles



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