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.
To set an environment variable everytime, use the export command in the . bashrc file (or the appropriate initialization file for your shell). To set an environment variable from a script, use the export command in the script, and then source the script. If you execute the script it will not work.
You can use variables as in any programming languages. There are no data types. A variable in bash can contain a number, a character, a string of characters. You have no need to declare a variable, just assigning a value to its reference will create it.
The “printenv” command displays the currently active environment variables and the previously specified environment variables in the shell. You can see the output of using the “printenv” command to display all the environment variables in the shell as per the snapshot below.
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"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With