Search code examples
shellscriptingposixlocalecurrency

how to determine currency symbol of current locale in POSIX shell script?


ahoy all.

while finding a few answers related to determining the locale's decimal separator (AKA radix point, thousands separator) in a shell script, the only answers that i have found related to obtaining the currency symbol of the current locale are specific to a programming language (e.g. PHP, Java, etc). however surprisingly i cannot yet find a solution which can be used in a POSIX shell script. i have come across references to locale variables like LC_MONETARY and LC_CURRENCY but have not yet stumbled upon a way to access them from the shell as they are not in the default environment of a normal bash/dash login.

as always thanks for reading and for any answers and comments.

peace.


Solution

  • after some more spelunking in the locale command i have discovered the following method for getting the currency symbol of the current locale:

    locale currency_symbol
    

    this command and keyword returns the appropriate currency symbol of the current locale

    $ LANG=it_IT.UTF-8 locale currency_symbol
    €
    
    $ LANG=en_US.UTF-8 locale currency_symbol
    $
    

    of course any other solutions and options, including ones that avoid the execution of an external command (i.e. locale) and a sub-process, are always appreciated :)