11

Complete C++ i18n gettext() “hello world” example. sets the LANG environment variable using export before executing the program (Linux):

export LANG=es_MX.utf8
./hellogt

Is there a way to set the language just while executing hellogt, like a command line argument? This would be handy for testing programs.

2 Answers 2

11

In ksh, bash, and similar shells,

LANG=es_MX.utf8 ./hellogt

will set LANG=es_MX.utf8 only for the invocation of ./hellogt.

More portably, there is a program called env

env LANG=es_MX.utf8 ./hellogt

which will set environment variables and run the program specified. This works in all shells, including csh and traditional sh (which do not support the first method).

8

You mean something like:

LANG=es_MX.utf8 ./hellogt

? Or maybe you mean you want to parse the commandline (argv), find the language passed in, and pass it to setlocale?

2
  • For testing programs so without modifying the code. Commented Jun 23, 2009 at 16:51
  • So, the first one.
    – Tanktalus
    Commented Jun 23, 2009 at 17:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.