0

I'm curious about learning about choosing correct env. variables. How to make out setting what env. variable would get the job done

Example:

if you want to make sure that command history always written immediately, you can put that command into your PROMPT_COMMAND variable (curiosity rose from this solution):

export PROMPT_COMMAND='history -a'

This is my dilemma: how was PROMPT_COMMAND chosen to get the job done. How do I acquire this talent?

2

3 Answers 3

3

If you're using bash as your default shell, you can indeed set PROMPT_COMMAND.

You usually find hints or detailed guidelines in the manual pages of a command (online from the bash man page) or by typing man bash for example:

PROMPT_COMMAND
If set, the value is executed as a command prior to issuing each primary prompt.

I did propose another solution using this env var a while ago: Adding a suffix at the end of each shell command.

Ask Ubuntu is a gold mine for who wants to learn and discover more about Linux.

0
1

Read the man page of the program you are trying to influence with an environment variable. For PROMPT_COMMAND it's man bash. Since programs generally use all upper case environment variables, and environment variables are passed to programs as strings, (in the env array, along with the argv array) and accessed by name, you can generate a list including all the environment variables looked at by a program via (change bash to the program you're interested in):

strings $(type -p bash) | egrep '^[A-Z0-9]+$'

Or replace the $(type -p bash) with the actual path to the binary.

User setting of environment variables is usually done in ~/.bashrc, or in a file called by ~/.bashrc, like this:

export LESS="-XMersj3"

This sets my default options for less (See man less).

After a change to ~/.bashrc, you must source the file (via . ~/.bashrc) to populate your environment with the updated definitions. Logging out/in also re-sources ~/.bashrc, BUT if you've broken ~/.bashrc, you may have trouble logging in.

0

how was PROMPT_COMMAND chosen to get the job done

PROMPT_COMMAND is one of the variables specific to bash, which runs its value as a command before printing your $PS1 prompt on screen. By default it's unset.

How to make out setting what env. variable would get the job done

By reading the man page of bash, man bash in terminal. There is list of environment variables there. There is no talent, only practice. And RTFM'ing, a lot.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .