Bash – Does Bash imitate Locale-Specific Translation from C

bashcstring

Bash manual mentions that

3.1.2.5 Locale-Specific Translation

A double-quoted string preceded by a dollar sign (‘$’) will cause the
string to be translated according to the current locale. If the
current locale is C or POSIX, the dollar sign is ignored. If the
string is translated and replaced, the replacement is double-quoted.

Does this way of specifying a string literal exist in C language or some C library?

Does bash imitate this way from C?

Best Answer

$"..." is Bash's way of accessing GNU gettext translations. In C code it would generally be gettext("...") or _("..."). Bash uses the system's default message catalog; a C application could also load up any catalogs it wanted to use.

The $" syntax is a Bash extension to resemble the existing parameter expansion syntax, and I suppose particularly the $' ANSI-C quoting it took from ksh and which may make it into POSIX in future. The C language does not support or have a parallel for the syntax itself.

Related Question