views:

3714

answers:

4

In tcsh, I have the following simple 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

My question is, what is the equivalent to the tcsh setenv function in bash? Is there a direct analog? The environment variables are for locating the executable.

UPDATE: Thanks everyone for your help! I'd been trying to figure this out for quite a while.

+3  A: 

I think you're looking for export - though I could be wrong.. I've never played with tcsh before. Use the following syntax:

export VARIABLE=value
Oli
+3  A: 

export VAR=value will set VAR to value. Enclose it in single quotes if you want spaces, like export VAR='my val'. If you want the variable to be interpolated, use double quotes, like export VAR="$MY_OTHER_VAR".

mipadi
+2  A: 

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.

iny
doesn't it give it to parent processes, not childs? If a shell script does an export, then the shell I invoked it with has that variable, IIRC.
rmeador
No. "are marked for automatic export to the environment of subsequently executed commands.", meaning child processes executed after the export.
iny
out of curiousity, where is that citation from?
pbh101
It is from bash command `help export`.
iny
+3  A: 

The reason people often suggest writing

VAR=value
export VAR

instead of the shorter

export VAR=value

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.

zaphod