Bash Configuration

Setting the environment (bash)

For this example, ‘$HOME/.bashrc’ will be used as the target RC file.

Other choices include

  • ‘$HOME/.login’

  • ‘$HOME/.bash_profile’

  • ‘$HOME/.profile’

Define constants (bash)

Assuming this help guide has not been followed before..

~ $ RC=$HOME/.bashrc
~ $ printf '\n# Developer environment\n' >> $RC
~ $ printf '#\n# Local paths\n#\n' >> $RC
~ $ printf "export PREFIX=\$HOME/.local\n" >> $RC
~ $ printf "export BIN=\$PREFIX/bin\n" >> $RC
~ $ printf "export CONFIG_DIRS=\$PREFIX/etc\n" >> $RC
~ $ printf "export VAR_DIR=\$PREFIX/var\n" >> $RC
~ $ printf "export LOG_DIR=\$VAR_DIR/log\n" >> $RC
~ $ printf "export PID_DIR=\$VAR_DIR/pid\n" >> $RC
~ $ printf "export USERCONFIG_DIRS=\$HOME/.config\n" >> $RC
~ $ printf "export PATH=\$PREFIX/bin:\$PATH\n" >> $RC
~ $ printf "export PROJECTS=\$HOME/projects\n" >> $RC
~ $ printf "export GITROOT_DIR=\$HOME/git\n" >> $RC

Note

The initial ‘printf’ statement, is a comment and includes both a leading and trailing “\n

This serves two purposes:

  1. The last entry isn’t clobbered (when the file is not posix compliant).

  2. Enables continuation with a compliant posix line file.

The second ‘printf’ statement is another comment, serving as a reminder to what is being set.

Each line there-after is solely terminated with the lineending character \n.

The following environment variables (env_vars or ENV) are now available in new shell sessions: [persistent-vars]

  1. PREFIX, location prefix

  2. BIN, location of executables

  3. CONFIG_DIRS, location of configuration files

  4. VAR_DIR, location of variable directories/files e.g. log directories

  5. LOG_DIR, location of log directories

  6. PID_DIR, location of pid files

  7. USERCONFIG_DIRS, location of user configuration files

  8. PATH, prepends the local bin directory to the existing PATH variable

  9. PROJECTS, location of projects

  10. GITROOT_DIR, location of git repositories

The purpose of the CONFIG_DIRS directory is to serve as a primary source of configuration template files that can be manipulated pragmatically.

Congratulations, a shell baseline environment is now defined!

Alternative RC/shells

If one of the other rc files is used, ensure it’s source’ed in the shell RC

~ $ cat $HOME/.bashrc
...
source /path/to/rc
...

See also

For other types of shell, the wikipedia article has a nice summary:

Todo

environment for shells-not-bash

[ ] fish

[ ] zsh

[persistent-vars]

Upon new login, these variables will be available within the session, including X/Wayland.