A set of dynamic variables that can affect the running processes.

learn more… | top users | synonyms

69
votes
4answers
110k 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 ...
42
votes
1answer
4k 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 ...
35
votes
4answers
2k 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...
34
votes
2answers
2k 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?
32
votes
4answers
1k views

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 ...
31
votes
4answers
11k 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 ...
28
votes
5answers
70k 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. ...
20
votes
3answers
5k 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 ...
19
votes
3answers
7k 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?
19
votes
3answers
750 views

Show PATH in a human-readable way

I want to show my PATH environment variable in a more human-readable way. $ echo $PATH ...
19
votes
5answers
569 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 ...
17
votes
6answers
15k 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> ...
16
votes
6answers
5k 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 ...
16
votes
1answer
3k 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 ...
14
votes
2answers
7k 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.
14
votes
6answers
22k 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 ...
13
votes
6answers
401 views

How do I source another process's environment variables?

If I examine /proc/1/environ I can see a null-byte-delimited string of process 1's environment variables. I'd like to bring these variables into my current environment. Is there an easy way to do ...
13
votes
2answers
6k 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: ...
13
votes
4answers
743 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 ...
11
votes
2answers
3k 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?
11
votes
2answers
2k 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?
11
votes
3answers
5k 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?
11
votes
4answers
2k views

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 ...
10
votes
2answers
2k 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 ...
10
votes
2answers
847 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 ...
10
votes
1answer
263 views

How do you set up the environment for es?

I've been playing with es the last couple of days, and it (like rc) has the quirk/feature that it only runs its startup script (.esrc) on login. The usual way to run code in each interactive session ...
9
votes
4answers
6k 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?
9
votes
2answers
3k 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 ...
9
votes
2answers
4k 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 - ...
9
votes
4answers
5k views

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 ...
9
votes
2answers
204 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
4answers
6k 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 ...
8
votes
2answers
1k views

How do you make RPROMPT in zsh update itself on every enter?

My RPROMPT is set to display svn info using vcs_info. It reads RPROMPT=${vcs_info_msg_0_}. vcs_info is called using precmd(). However, RPROMPT doesn't update when I change directories. It works only ...
8
votes
2answers
168 views

using export in .bashrc

I have noticed in my .bashrc, that some lines have export in front, such as export HISTTIMEFORMAT="%b-%d %H:%M " ... export MYSQL_HISTFILE="/root/.mysql_history" whereas other have not, such as ...
8
votes
2answers
540 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 ...
8
votes
1answer
2k views

What's the difference between “export” and “setenv”?

What's the difference between export and setenv?
7
votes
2answers
7k views

JAVA_HOME not set in script when run using sudo

I'm trying to run an install script that requires java to be installed and the JAVA_HOME environment variable to be set. I've set JAVA_HOME in /etc/profile and also in a file I've called java.sh in ...
7
votes
2answers
372 views

Set the language for a single program execution

Complete C++ i18n gettext() “hello world” example. sets the LANG environment variable using export before executing the program (Linux): export LANG=es_MX.utf8 ./hellogt Is there a way to set the ...
7
votes
3answers
1k views

Why $SHELL doesn't change when I run new shell?

$ echo $SHELL /bin/bash $ /bin/ksh93 $ echo $SHELL /bin/bash $ file /bin/ksh93 /bin/ksh93: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for ...
7
votes
1answer
1k 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 ...
7
votes
1answer
268 views

How set environment variable based on whether a GUI is available?

How can I set up my .bashrc such that the value of an environment variable changes based on whether or not the current session has access to the gui / windowing system? For example, let's say I have ...
7
votes
1answer
4k views

How to reset a shell environment?

This issue has been bugging me for a while, and although I've taught I've found my answer through EnvWatcher, unfortunately it only works on Bash. And I use zsh. I would like to replicate the things ...
7
votes
2answers
416 views

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 ...
7
votes
1answer
864 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. ...
6
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 ...
6
votes
2answers
5k views

How to alter PATH within bash script?

I have several projects that require me to change versions of Java/Grails/Maven. I'm trying to handle this with some Bash scripts that would make the changes. For example: #!/bin/sh export ...
6
votes
5answers
441 views

PATH environment variable in linux

I want to know how the standard environment variables given by the linux OS like PATH, HOME are set automatically. In which file are these read from. There should be some file from which these ...
6
votes
2answers
4k 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 ...
6
votes
1answer
914 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 ...
6
votes
5answers
5k 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 ...