Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

export LANG=es_MX.utf8

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

share|improve this question

migrated from stackoverflow.com Feb 12 '11 at 20:21

This question came from our site for professional and enthusiast programmers.

up vote 9 down vote accepted

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).

share|improve this answer

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?

share|improve this answer
For testing programs so without modifying the code. – C.W.Holeman II Jun 23 '09 at 16:51
So, the first one. – Tanktalus Jun 23 '09 at 17:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.