Questions tagged [environment-variables]

A set of dynamic variables that can affect the running processes behavior and access to resources.

Environment variables in determine the behavior and access in the system. Some of the settings are contained within configuration settings and others are determined by user input. The shell keeps track of all the settings in the environment, that builds every time it starts a session with variables, defining system properties.

Shell variables are shown with the set command:

$ set
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()

Common environment variables

PATH – a list of directory paths. When the user types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command.

HOME – dictates where a user's home directory is located in the filesystem.

TERM – specifies the type of computer terminal or terminal emulator being used (e.g. xterm-256color)

SHELL - default shell

PWD - prints current working directory

MAIL – used to indicate where a user's mail is to be found

To show an environment variable use the command echo $<environment-variable> (e.g. echo $PATH).

1042 questions
996
votes
17 answers

How to add a directory to the PATH?

How do I add a directory to the $PATH in Ubuntu and make the changes permanent?
0xnuminous
  • 11,280
556
votes
11 answers

How to list all variables names and their current values?

How to list all variables names and their current values? Including not only $HOME, $PWD etc but any other you have defined.
Strapakowsky
  • 12,304
408
votes
9 answers

How to see time stamps in bash history?

Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also? Bottom-Line: Execution time in the Bash history
Raja G
  • 105,327
  • 107
  • 262
  • 331
257
votes
7 answers

Why ~/.bash_profile is not getting sourced when opening a terminal?

Problem I have an Ubuntu 11.04 Virtual Machine and I wanted to set up my Java development environment. I did as follows sudo apt-get install openjdk-6-jdk Added the following entries to ~/.bash_profile export…
Viriato
  • 2,781
  • 3
  • 16
  • 10
220
votes
3 answers

BASH script to set environment variables not working

I have written the following script to set some environment variables when needed: #!/bin/sh export BASE=/home/develop/trees echo $BASE export PATH=$PATH:$BASE echo $PATH Below the command and the results I can see on my terminal: the script runs,…
MirkoZa
  • 2,311
198
votes
8 answers

How do I set environment variables?

I'm trying to set up Apache Tomcat on my pc, and it wants me to set up an environment variable for CATALINA_HOME. Does any know how to do this?
jumpnett
  • 6,185
148
votes
6 answers

Setting PATH variable in /etc/environment vs .profile

Where is the preferred place to set the PATH envvar? ~/.profile or /etc/environment? What is the case when PATH is set in both places? Is the end result a concatenation of both values set in those two places?
pkaramol
  • 2,291
141
votes
3 answers

Set variable in .desktop file

Is there a way to set the enviroment variable in .desktop file? I'm trying to run application (eclipse) with custom gtk style, so basically I want to get the following result by runing a .desktop file: GTK2_RC_FILES=gtkrc.custom…
dotintegral
  • 1,413
133
votes
5 answers

What is the $DISPLAY environment variable?

I am new to shell scripting. I don't understand what the $DISPLAY environmental variable is. I have Ubuntu 13.10 and I use /bin/bash shell. I have two monitors. Questions: Command echo $DISPLAY will print :0.0 on my machine (on both monitors). What…
94
votes
1 answer

How does sudo handle $HOME differently since 19.10?

In Ubuntu releases prior to Ubuntu 19.10 Eoan Ermine, when I run a command with sudo, that command receives my home directory in the $HOME environment variable. This is the behavior I have long expected and warned other people about. If I want sudo…
87
votes
10 answers

How do I modify my PATH so that the changes are available in every Terminal session

I want to add a directory to search my search path. I know I have to modify the PATH environment variable. However, I want the change to be permanent, so that it is always in effect, for every Terminal (bash) window I open. There is an overload of…
84
votes
5 answers

Environment variable vs Shell variable, what's the difference?

Somebody told me that: BASH isn't an environment variable, it's a shell variable What's the difference?
Student
  • 12,236
82
votes
4 answers

Permanent PATH variable

How will I make this /media/De Soft/mongodb/bin PATH variable permanent? Everyone is saying "export PATH=$PATH:media/De\ Soft/mongodb/bin to your ~/.profile, or .bashrc, or .zshenv depending on your shell". I don't know what is ~/.profile, or…
Towhid
  • 4,195
81
votes
2 answers

Why isn't .profile sourced when opening a terminal?

Just installed Ubuntu 14.04.1 LTS. According to .profile, # ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash, if ~/.bash_profile or ~/.bash_login exists. There is no ~/.bash_profile or…
B Seven
  • 1,069
71
votes
4 answers

Where to declare environment variables?

What are correct places for: Global environment variables meant to affect all users? User-specific environment variables?
Ivan
  • 58,745
1
2 3
69 70