The environment-variables tag has no wiki summary.
18
votes
4answers
1k views
Alternative to .bashrc
Is ~/.bashrc the only place where I can specify user specific ENV Variables, aliases, modifications to PATH variable, etc?
I ask because it seems that ~/.bashrc would be bash only...
17
votes
4answers
5k 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 ...
23
votes
2answers
1k 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?
11
votes
4answers
28k 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.
...
28
votes
4answers
35k views
How to correctly add a path to PATH?
I'm wondering where a new path has to be added to PATH environment variable. I know this is accomplished editing .bash_rc (for example), but it's not clear how to do this.
This way:
export ...
6
votes
2answers
1k views
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 ...
3
votes
2answers
367 views
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 ...
2
votes
2answers
899 views
Is there a way to push shell config information when SSHing to a host?
I know how to set the GNOME-terminals (or xterms!) prompt to green/red regarding the last exit code:
vi .bashrc
export PROMPT_COMMAND='PS1="`
if [[ \$? = "0" ]];
then echo "\\[\\033[0;32m\\]";
else ...
10
votes
4answers
541 views
keep duplicates out of $PATH on source
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 ...
8
votes
2answers
172 views
best way to set up separate linux environment in ~
I do most of my work (involves a lot of C/Python) on a development server that is shared with several other people. As a result we all seem to do a bit of the system administration chores (there is ...
8
votes
2answers
1k views
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 ...
15
votes
5answers
422 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 ...
11
votes
1answer
2k views
Difference between environment variables and exported environment variables 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 ...
5
votes
2answers
2k views
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 ...
30
votes
1answer
2k 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 ...
7
votes
2answers
246 views
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 ...
4
votes
2answers
2k 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 - ...
5
votes
1answer
460 views
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 ...
4
votes
4answers
2k 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 ...
2
votes
2answers
475 views
How to change environment variables without re-logging to UI?
How can I change environment variables without re-logging to UI?
I want to re/define some variables and want them set on my current logged in shell (including UI). I know logging out and then logging ...
12
votes
3answers
3k views
How to print all environment variables defined (but not necessarily exported) in bash
The bash builtin command set, if invoked without arguments, will print all environment variables, but also all defined functions. this makes the output unusable for humans and difficult to grep.
How ...
5
votes
1answer
479 views
How can I make variables “exported” in a bash 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 ...
4
votes
3answers
169 views
Is it possible to find out which files are setting/adding to environment variables, and their order of precedence?
Some of my environment variables ($PATH, $MANPATH and friends) are partially set up in different source files.
I find myself wishing for a command or method to quickly gather what part, in a specific ...
3
votes
1answer
1k views
dot file not sourced when running a command via ssh
When I run my program interactively, it works fine:
ssh somehost
$ ~/some/path/somescript.py
When I run my program over ssh directly, it doesn't work. The variable PYTHONPATH is not set, because ...
5
votes
3answers
2k views
How to read environment variables of a process
Linux's /proc/<pid>/environ does not update (as I understand it, the file contain the initial environment of the process).
How can I read a process's current environment?
4
votes
2answers
2k views
How to get a clean environment in a ksh shell?
I need to get rid of all the environment variables in a Ksh shell. I can fork a new instance, but it will inevitably source some init files (as far as I know .profile, .kshrc). Is there a way to ...
14
votes
3answers
3k 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 ...
13
votes
5answers
7k views
How can I run a script immediately after connecting via SSH?
I started to ask this question but answered it while I had it open. I'm going to post this question, follow it up with my solution and leave it open to other potential solutions.
<backstory>
...
8
votes
2answers
1k 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:
...
9
votes
4answers
2k 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?
7
votes
2answers
295 views
How can I create a clean shell environment for temporary use?
I am a frequent answerer on a Unix-focused popular Q&A site, and in many of my answers I provide examples using the bash shell. However, each time I do this I have to manually go through the ...
5
votes
4answers
2k views
Run script in a non interactive shell?
I have a cron job that is running a script. When I run the script via an interactive shell (ssh'ed to bash) it works fine. When the script runs by itself via cron it fails.
My guess is that it is ...
8
votes
2answers
361 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?
7
votes
3answers
130 views
+100
Why do I have to re-set env vars in tmux when I re-attach?
I mainly work on a mac and ssh/tmux attach to a Linux machine to do my work. I have ssh-agent running on the Linux machine. I have
set -g update-environment "SSH_AUTH_SOCK SSH_ASKPASS WINDOWID ...
6
votes
1answer
567 views
Where have I set my bash PATH?
I want to remove ~/bin from my PATH. I set it up months ago when Linux (Ubuntu) was very new to me, but I don't know how I added it...
Nothing shows up when I search all the files listed below.
...
5
votes
4answers
2k views
Adding paths to PATH using a multi-line syntax
As far as I understand, the usual way to add a path to the PATH environment variable is by concatenating paths separated by the : character.
For example, if I want to add three paths to it ...
0
votes
1answer
160 views
difficalty to save traceroute output in shell variable?
I need to filter and store traceroute output in shell variable (array). But I am getting some unusual output.
As I try to explain in following lines.
My present directory is temp, having some ...
5
votes
2answers
349 views
Isn't $HOME supposed to be the location of the user's home directory?
I'm having trouble with a web application I'm writing: The web application, which runs as user nobody, needs to launch an inkscape process to manipulate some SVG files. Because this runs as user ...
4
votes
2answers
2k views
Is it possible to export env variable via Upstart?
I need to export a variable FOO=stringhere so that system processes could use it. And the place I would like to do this, is Upstart job.
Unfortunately, I tried as per Upstart manual to do env ...
2
votes
3answers
136 views
What is the difference between ./script and . ./script? [duplicate]
Possible Duplicate:
Using ‘.’ to execute files in bash
I was trying to figure out how to export my environmental via script instead of changing my .bashrc file.
I found this old useful ...
2
votes
2answers
663 views
Exception of inheritance of environment variables
Quoted from Wikipedia:
By default, when a process is created it inherits a duplicate
environment of its parent process, except for explicit changes made by
the parent when it creates the ...
1
vote
1answer
89 views
Set environment variable for all of tmux shells when gnome-sessions gets restarted
To solve this problem, I need to set the environment variable DBUS_SESSION_BUS_ADDRESS for all shells inside tmux every time I restart gnome without restarting tmux (this is often). How can I best ...
1
vote
1answer
535 views
pass 1 environment variable using sudo
Is this a correct way for passing an environment variable in sudo ?
sudo -u www-data -b env FOOBAR="foobar" /home/user/folder/daemon
0
votes
2answers
4k views
How to set environment variable JAVA_HOME that will be saved on exit? [duplicate]
Possible Duplicate:
How do I set a user environment variable? (permanently, not session)
I use Suse. First was installed jdk7, so JAVA_HOME remains like:
/usr/java/jdk1.7.0_05/
After I ...
