2022 Developer Survey is open! Take survey.

Questions tagged [environment-variables]

For questions pertaining to environment variables, a set of dynamic variables that can affect the running processes behavior and access to resources. Use this tag for questions about environment variables or questions about issues arising from the impact of setting or modifying the variables value in running processes behavior and access to resources.

Filter by
Sorted by
Tagged with
1239 votes
12 answers
3.0m views

How to correctly add a path to PATH?

I'm wondering where a new path has to be added to the PATH environment variable. I know this can be accomplished by editing .bashrc (for example), but it's not clear how to do this. This way: export ...
user avatar
  • 15.6k
434 votes
6 answers
374k views

What does "LC_ALL=C" do?

What does the C value for LC_ALL do in Unix-like systems? I know that it forces the same locale for all aspects but what does C do?
user avatar
  • 8,730
316 votes
4 answers
1.2m views

How to permanently set environmental variables

My variables are LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64 How to save these variables permanently ?
user avatar
  • 14.4k
308 votes
5 answers
487k views

How do I set an environment variable on the command line and have it appear in commands?

If I run export TEST=foo echo $TEST It outputs foo. If I run TEST=foo echo $TEST It does not. How can I get this functionality without using export or a script?
user avatar
242 votes
9 answers
173k views

How to determine where an environment variable came from?

I have a Linux instance that I set up some time ago. When I fire it up and log in as root there are some environment variables that I set up but I can't remember or find where they came from. I've ...
user avatar
  • 2,523
238 votes
5 answers
60k views

VISUAL vs. EDITOR – what’s the difference?

I generally set both VISUAL and EDITOR environment variables to the same thing, but what's the difference? Why would I set them differently? When developing apps, why should I choose to look at VISUAL ...
user avatar
190 votes
5 answers
86k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
user avatar
171 votes
6 answers
550k views

How do I set a user environment variable? (permanently, not session)

This is irritating me. I seen several suggestions (all using different files and syntax) and none of them worked. How do I set an environment variable for a specific user? I am on debian squeeze. ...
user avatar
161 votes
7 answers
116k views

How to run a program in a clean environment in bash?

I want to run a program in an empty environment (i.e. with no envariables set). How to do this in bash?
user avatar
149 votes
11 answers
311k views

How can I run a cron command with existing environmental variables?

How can I run a cron command with existing environmental variables? If I am at a shell prompt I can type echo $ORACLE_HOME and get a path. This is one of my environmental variables that gets set in ...
user avatar
  • 41.3k
131 votes
4 answers
63k views

Is there a ".bashrc" equivalent file read by all shells?

Is ~/.bashrc the only place to specify user specific environment variables, aliases, modifications to PATH variable, etc? I ask because it seems that ~/.bashrc seems to be bash-only, but other ...
user avatar
  • 23.5k
115 votes
11 answers
304k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
user avatar
  • 1,253
109 votes
6 answers
46k views

Why is setting a variable before a command legal in bash?

I've just encountered several answers such as to parsing a delimited text file... that use the construct: while IFS=, read xx yy zz;do echo $xx $yy $zz done < input_file where the IFS ...
user avatar
  • 1,195
106 votes
6 answers
43k views

What is the difference between 'env' and 'printenv'?

What is the difference between the two commands env and printenv? They both show the environment variables, and the output is exactly the same aside from _. Are there any historical reasons for there ...
user avatar
  • 1,223
102 votes
5 answers
63k views

If processes inherit the parent's environment, why do we need export?

I read here that the purpose of export in a shell is to make the variable available to sub-processes started from the shell. However, I have also read here and here that "Processes inherit their ...
user avatar
98 votes
4 answers
124k views

Why is `while IFS= read` used so often, instead of `IFS=; while read..`?

It seems that normal practice would put the setting of IFS outside the while loop in order to not repeat setting it for each iteration... Is this just a habitual "monkey see, monkey do" style, as it ...
user avatar
  • 31k
96 votes
10 answers
119k views

Replace environment variables in a file with their actual values?

Is there an easy way to substitute/evaluate environment variables in a file? Like let's say I have a file config.xml that contains: <property> <name>instanceId</name> <...
user avatar
91 votes
3 answers
142k views

Replacing only specific variables with envsubst

I'm trying to perform environment variable replacement through envsubst, but I want to only replace specific variables. From the docs I should be able to tell envsubst to only replace certain ...
user avatar
  • 1,013
87 votes
2 answers
347k views

sudo as another user with their environment

$ whoami admin $ sudo -S -u otheruser whoami otheruser $ sudo -S -u otheruser /bin/bash -l -c 'echo $HOME' /home/admin Why isn't $HOME being set to /home/otheruser even though bash is invoked as a ...
user avatar
  • 1,429
87 votes
2 answers
23k views

Is there ever a good reason to run sudo su?

To launch a root shell on machines where the root account is disabled, you can run one of: sudo -i : run an interactive login shell (reads /root/.bashrc and /root/.profile) sudo -s : run a non-login ...
user avatar
  • 215k
82 votes
4 answers
132k views

How can I make environment variables "exported" in a shell script stick around?

I have multiple Amazon EC2 accounts and want to quickly be able to switch variables, such as $EC2_HOME, using a script. I have have a shell script set up like this: #!/bin/sh export EC2_HOME=/home/...
user avatar
  • 41.3k
80 votes
4 answers
99k views

How do I change the default text editor in the Debian (squeeze) distro

"Joe's own editor" does not come naturally to me. How do I change to using nano or vim? I've tried export EDITOR=nano but it doesn't seem to be respected. I'd like visudo to respect this as well.
user avatar
  • 901
79 votes
5 answers
190k views

Refresh env variables after editing bashrc file

I frequently edited the .bashrc file to export new environment variables. Rather than close the console and start a new one to refresh the env variables, is there a convenient way to refresh?
user avatar
  • 1,545
78 votes
5 answers
100k views

How do I start all shell sessions in a directory other than $HOME?

When I open my non-login shell in Ubuntu, my present working directory is /home/user_name (my $HOME environment variable), but I want to change this such that when I start my terminal I am in some ...
user avatar
75 votes
3 answers
48k views

How does /usr/bin/env know which program to use?

When I use the shebang #!/usr/bin/env python to run a script, how does the system know which python to use? if I look for a python bin path in the environment variables I find nothing. env | grep -i ...
user avatar
  • 1,095
73 votes
8 answers
30k views

Multiple arguments in shebang

I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!). I use NixOS, and the first part of the shebang in any script I write is usually /...
user avatar
73 votes
3 answers
67k views

What is the difference between ~/.profile, ~/.bashrc, ~/.bash_profile, ~/.gnomerc, /etc/bash_bashrc, /etc/screenrc ...?

Answers to the questions on SO and askubuntu, along with poking through (and reading headers of) $HOME and /etc/, indicate a number of files that can be used to set environment variables, including: ~...
user avatar
  • 1,611
70 votes
3 answers
24k views

Shebang line with `#!/usr/bin/env command --argument` fails on Linux

I've got a simple script: #!/usr/bin/env ruby --verbose # script.rb puts "hi" On my OSX box, it runs fine: osx% ./script.rb hi However, on my linux box, it throws an error linux% ./script.rb /usr/...
user avatar
  • 1,491
66 votes
8 answers
75k views

Makefile include env file

I'm trying to include some env vars into a Makefile. The env file looks like: FOO=bar BAZ=quux Note there's no leading export to each env var. If I add the leading export and just include the env ...
user avatar
66 votes
4 answers
24k views

Show PATH in a human-readable way

I want to show my PATH environment variable in a more human-readable way. $ echo $PATH /Users/arturo/.rvm/gems/ruby-1.9.3-p392/bin:/Users/arturo/.rvm/gems/ruby-1.9.3-p392@global/bin:/Users/arturo/....
user avatar
62 votes
9 answers
32k views

How to print only defined variables (shell and/or environment variables) in bash

The bash builtin command set, if invoked without arguments, will print all shell and environment variables, but also all defined functions. This makes the output unusable for humans and difficult to ...
user avatar
  • 25.2k
62 votes
3 answers
78k views

Using export in .bashrc

I have noticed in my .bashrc that some lines have export in front of them, such as export HISTTIMEFORMAT="%b-%d %H:%M " ... export MYSQL_HISTFILE="/root/.mysql_history" whereas others don't, such ...
user avatar
60 votes
16 answers
255k views

Removing a directory from PATH

I'm trying to compile wxWidgets using MingW, and I have cygwin in my path, which seems to conflict. So I would like to remove /d/Programme/cygwin/bin from the PATH variable and I wonder if there is ...
user avatar
  • 721
59 votes
2 answers
76k views

get environment variable by variable name? [duplicate]

For example, I have a variable: env_name="GOPATH" Now I want to get the environment variable GOPATH as if like this: echo $GOPATH How can I get $GOPATH by $env_name?
user avatar
  • 729
58 votes
3 answers
102k views

How to make unix service see environment variables?

I have set my environment variable using /etc/profile: export VAR=/home/userhome Then if I do echo $VAR it shows /home/userhome But when I put reference to this variable into the /etc/init.d/...
user avatar
  • 1,710
57 votes
3 answers
97k views

Exporting a variable with dot (.) in it

How to export a variable which has dot in it. I get 'invalid variable name' when I tried : export my.home=/tmp/someDir -ksh: my.home=/tmp/someDir: invalid variable name Even escaping metacharacter ...
user avatar
55 votes
5 answers
76k views

How to read environment variables of a process

Linux's /proc/<pid>/environ does not update a process's environment. As I understand it, the file contains the initial environment of the process. How can I read a process's current environment?
user avatar
55 votes
10 answers
88k views

Can shell variable name include a hyphen or dash (-)?

I am not able to use - in variables in shell. Is there a way to be able to use it, because I have one script which depends on such named variables: $export a-b=c -bash: export: `a-b=c': not a valid ...
user avatar
  • 2,635
54 votes
8 answers
59k views

Why are PATH variables different when running via sudo and su?

On my fedora VM, when running with my user account I have /usr/local/bin in my path: [justin@justin-fedora12 ~]$ env | grep PATH PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/...
user avatar
53 votes
2 answers
132k views

What is $PWD? (vs current working directory)

So Wikipedia (link) tells me that the command pwd is short for "print working directory", and that makes sense. But for the environment variable, the "P" has to be an acronym for something else than ...
user avatar
53 votes
1 answer
26k views

Difference between shell variables which are exported and those which are not in bash

Bash seems to differentiate between variables which have been exported and those which have not. example: $ FOO=BAR $ env | grep FOO $ set | grep FOO FOO=BAR set sees the variable but env does not. ...
user avatar
  • 25.2k
51 votes
3 answers
51k views

.bash_profile not sourced when running su

I have a user, say user1, which has modifications to its .bash_profile, one of them changing the PATH, e.g.: export PATH=/some/place:$PATH. This change works fine if I log on as user1 or do a su - ...
user avatar
  • 1,023
50 votes
6 answers
41k views

What's the 'right' format for the HTTP_PROXY environment variable? Caps or no caps?

I've encountered both http_proxy and HTTP_PROXY. Are both forms equivalent? Does one of them take precedence over the other?
user avatar
  • 962
49 votes
4 answers
248k views

"not a valid identifier" when I do "export $PATH"

When I run export $PATH in bash, I get the error not a valid identifier. Why?
user avatar
  • 641
49 votes
4 answers
104k views

Who sets $USER and $USERNAME environment variables?

Also, will these variables always match currently logged-in username (they do on my Debian system)? Can I assume their availability in other Unix(-like) systems? I'm also curious why one would use ...
user avatar
  • 60.7k
47 votes
5 answers
99k views

how to pass environment variable to sudo su

I basically need to do this: DUMMY=dummy sudo su - ec2-user -c 'echo $DUMMY' This doesn't work. How can I pass the env variable $DUMMY to su? -p doesn't work with -l.
user avatar
  • 573
47 votes
5 answers
65k views

What scopes can shell variables have?

I just ran into a problem that shows me I'm not clear on the scope of shell variables. I was trying to use bundle install, which is a Ruby command that uses the value of $GEM_HOME to do its work. I ...
user avatar
  • 1,543
46 votes
2 answers
42k views

In zsh how can I list all the environment variables?

I want to get a list of all environment variables (shell variables? exported variables?) and their values at a given time, in zsh. What is the proper way to do this?
user avatar
  • 5,953
45 votes
5 answers
45k views

How is sudo set to not change $HOME in Ubuntu and how to disable this behavior?

On Ubuntu 12.04, when I sudo -s the $HOME variable is not changed, so if my regular user is regularuser, the situation goes like this: $ cd $ pwd /home/regularuser $ sudo -s # cd # pwd /home/...
user avatar
  • 1,085
45 votes
2 answers
53k views

what is `env <command>` doing?

What is the command env ls -al doing? I had a Linux test and there was question: "How to run command directly, but not its alias?" I knew that there exists solution like prefixing command with some ...
user avatar
  • 873

1
2 3 4 5
29