In tcsh
, I have the following script working:
#!/bin/tcsh
setenv X_ROOT /some/specified/path
setenv XDB ${X_ROOT}/db
setenv PATH ${X_ROOT}/bin:${PATH}
xrun -d xdb1 -i $1 > $2
What is the equivalent to the tcsh setenv
function in Bash?
Is there a direct analog? The environment variables are for locating the executable.
I think you're looking for
export
- though I could be wrong.. I've never played with tcsh before. Use the following syntax:The reason people often suggest writing
instead of the shorter
is that the longer form works in more different shells than the short form. If you know you're dealing with
bash
, either works fine, of course.Set a local and environment variable using Bash on Linux
Check for a local or environment variables for a variable called LOL in Bash:
Sanity check, no local or environment variable called LOL.
Set a local variable called LOL in local, but not environment. So set it:
Variable 'LOL' exists in local variables, but not environment variables. LOL will disappear if you restart the terminal, logout/login or run
exec bash
.Set a local variable, and then clear out all local variables in Bash
You could also just unset the one variable:
Local variable LOL is gone.
Promote a local variable to an environment variable:
Note that exporting makes it show up as both a local variable and an environment variable.
Exported variable DOGE above survives a Bash reset:
Unset all environment variables:
You have to pull out a can of Chuck Norris to reset all environment variables without a logout/login:
You created an environment variable, and then reset the terminal to get rid of them.
Or you could set and unset an environment variable manually like this:
VAR=value
sets VAR to value.After that
export VAR
will give it to child processes too.export VAR=value
is a shorthand doing both.export VAR=value
will set VAR to value. Enclose it in single quotes if you want spaces, likeexport VAR='my val'
. If you want the variable to be interpolated, use double quotes, likeexport VAR="$MY_OTHER_VAR"
.