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
142 votes
4 answers

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 ...
Stefan's user avatar
  • 25.2k
215 votes
4 answers

$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?
xenoterracide's user avatar
1359 votes
12 answers

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 ...
Paolo's user avatar
  • 17.3k
93 votes
4 answers

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/...
cwd's user avatar
  • 45.2k
489 votes
6 answers

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?
jcubic's user avatar
  • 9,912
146 votes
11 answers

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?
Sony Santos's user avatar
  • 1,563
95 votes
2 answers

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 ...
terdon's user avatar
  • 241k
183 votes
6 answers

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
105 votes
4 answers

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 ...
Peter.O's user avatar
  • 32.9k
288 votes
8 answers

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 ...
Joel's user avatar
  • 2,983
367 votes
5 answers

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?
ashleysmithgpu's user avatar
357 votes
4 answers

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 ?
user3021349's user avatar
  • 16.5k
37 votes
4 answers

What's the best distro/shell-agnostic way to set environment variables?

The question says it all. I currently use Arch Linux and the zsh, but I'd like a solution that (at minimum) works both on VTs and in xterms and also (hopefully, preferably) will continue to work if I ...
strugee's user avatar
  • 14.9k
46 votes
2 answers

Does ~ always equal $HOME

I know this has probably been asked before, but I couldn't find it with Google. Given Linux Kernel No configurations that change $HOME bash Will ~ == $HOME be true?
PythonNut's user avatar
  • 1,424
29 votes
4 answers

What is this shell/Bash syntax: someVariable=someValue someCommand [duplicate]

One of my coworkers has provided me with a Bash syntax that I am unfamiliar with. My Google foo has failed me on figuring out what it does and why/when I should use it. The command that he sent me ...
sixtyfootersdude's user avatar
56 votes
1 answer

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. ...
Lesmana's user avatar
  • 27.4k
128 votes
6 answers

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 ...
Mike Lippert's user avatar
  • 1,385
92 votes
8 answers

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 /...
Rastapopoulos's user avatar
60 votes
8 answers

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:/...
Justin Ethier's user avatar
47 votes
3 answers

change environment of a running process

How might it be possible to alter some variable in the env of an already running process, for example through /proc/PID/environ? That "file" is read-only. Need to change or unset the DISPLAY variable ...
Marcos's user avatar
  • 2,305
24 votes
2 answers

Expansion of a shell variable and effect of glob and split on it

This post actually contains two separate questions but I think grouping them together will give some more context. I have gone through this question on quotes around variables but I do not quite ...
Geek's user avatar
  • 6,658
77 votes
3 answers

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/...
rampion's user avatar
  • 1,639
32 votes
5 answers

Complete view of where the PATH variable is set in bash

I've read in a couple of places that the PATH is set in /etc/profile or the .profile file that's in the home dir. Are these the only places that the path is set in? I want a better understanding of ...
Larry Lawless's user avatar
25 votes
2 answers

What is the difference between '.' and 'source' in shells? [duplicate]

Possible Duplicate: running script with “. ” and with “source ” I have used both the dot command '.' and 'source' to reload a given rc file (typically to update my environment variables) but I am ...
Ivar's user avatar
  • 353
112 votes
5 answers

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 ...
Amelio Vazquez-Reina's user avatar
77 votes
3 answers

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: ~...
Abe's user avatar
  • 1,681
70 votes
3 answers

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 ...
Martin Vegter's user avatar
64 votes
2 answers

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?
roger's user avatar
  • 779
17 votes
4 answers

What environment do I get with sudo?

When I run sudo, what exactly happens to my environment? When I run sudo command, it doesn't seem to see my or root's environment. For example, my path for both includes /usr/local/bin, but if I try ...
beatgammit's user avatar
  • 7,543
262 votes
6 answers

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 ...
xenoterracide's user avatar
161 votes
11 answers

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 ...
cwd's user avatar
  • 45.2k
54 votes
3 answers

.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 - ...
NullUser's user avatar
  • 1,063
53 votes
3 answers

Where does the TERM environment variable default get set?

When I open a terminal window with the GNOME Terminal emulator in the desktop GUI the shell TERM environment variable defaults to the value xterm. If I use CTL+ALT+F1 to switch to a console TTY ...
Andy Fusniak's user avatar
46 votes
5 answers

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/...
alekosot's user avatar
  • 1,105
15 votes
2 answers

In `while IFS= read..`, why does IFS have no effect?

I might have something absolutely wrong, but it looks convincing to me, that setting IFS as one of the commands in the pre-do/done list has absolutely no effect. The outer IFS (outside the while ...
Peter.O's user avatar
  • 32.9k
14 votes
3 answers

Indirectly expand variables in shell

I need to indirectly reference a variable in the bash shell. I basically want to what you can do in make by writing $($(var)). I have tried using ${$var} which would be the most straight forward ...
wefwefa3's user avatar
  • 1,385
65 votes
9 answers

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 ...
Lesmana's user avatar
  • 27.4k
50 votes
5 answers

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 ...
Nathan Long's user avatar
  • 1,613
38 votes
2 answers

What is the significance of single and double quotes in environment variables?

I defined some environment variables in my .profile like this: MY_HOME="/home/my_user" but the variable does not seem to evaluate unless I strip off the quotes and re-source the file. I believe the ...
2NinerRomeo's user avatar
26 votes
3 answers

How do I run GUI applications as root by using pkexec?

I am using Trisquel GNU/Linux-Libre which comes with Gnome3 Flashback Desktop Environment. I know that I can run GUI application as root by sudo & gksudo but I want to know that How do I run GUI ...
Pandya's user avatar
  • 24.5k
24 votes
3 answers

Is it possible to pass environment variables from child to parent in user space? [duplicate]

As the title says, I want to be able to change environment variables in a parent process (specifically, a shell) from a child process (typically a script).  From pseudo terminal /dev/pts/id trying to ...
Error's user avatar
  • 381
17 votes
2 answers

set LC_* but not LC_ALL

I'd like to have a German (Austria) locale (A4 paper size, 24 hour time, yyyy-mm-dd), but an English-language user interface (I don't like poor translations). I figured that the correct way to achieve ...
Heinzi's user avatar
  • 1,255
6 votes
1 answer

How to read value of variable, where the name of variable is the value of another variable

I think an example is in order. Consider I have these two environment variables setup (by a Continuous Delivery tool): PACKAGE_VER=1.2.3 and USE_VERSION_FROM=PACKAGE_VER. What I want now is a script ...
Fredrik Wendt's user avatar
100 votes
4 answers

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 ...
João Angelo's user avatar
  • 1,103
65 votes
7 answers

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
45 votes
4 answers

What exactly is an environment variable?

I know that VARIABLE=value creates an environment variable, and export VARIABLE=value makes it available to processes created by the current shell. env shows the current environment variables, but ...
Matt's user avatar
  • 813
27 votes
4 answers

keep duplicates out of $PATH on source [duplicate]

I have the following code that's source-d by my .shellrc PATH="${PATH}:${HOME}/perl5/bin" PATH="${PATH}:${HOME}/.bin" export PATH but if I make changes to other code and then source this file, my ...
xenoterracide's user avatar
19 votes
2 answers

Correctly setting environment

I'm using zsh and gdm to run gnome. Some time ago I discovered that variables are not set correctly. For example LANG/LC_ALL are incorrect ("" instead of en_GB.UTF-8). I split the .zshrc into .zshrc ...
Maciej Piechotka's user avatar
15 votes
1 answer

Location to place systemd service EnvironmentFile when creating debian package

I am currently rewriting upstart jobs to use systemd and I wanted to know: Where is the "default" place to an EnvironmentFile? It could potentially go in /etc/environment It could be with all the ...
Wimateeka's user avatar
  • 1,005
12 votes
2 answers

Interactive shell with environment identical to cron

I am aware of a lot of pitfalls in the magic world of crontabs, but sometimes it would help troubleshooting a lot when you have some smart way to enter an interactive (bash) shell with exact identical ...
jippie's user avatar
  • 14k

2 3 4 5 6