LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to set environment variable (https://www.linuxquestions.org/questions/linux-software-2/how-to-set-environment-variable-563023/)

yuan13452 06-19-2007 02:50 PM

How to set environment variable
 
I am relitively new to linux and just download a program. It ask me to set the environment variable VAR to the name of a directory.
I tried both in command line: "export VAR=/home/dir/"
but the system just say: "export: Command not found."
How can I set an environment variable?

Thanks

GregLee 06-19-2007 03:01 PM

The method you used should have worked. Just to be sure, I just tried it, and it worked for me. You must be typing into a bash shell, because it's bash that you're asking to export this variable with its value. You should also be able to pass VAR to the program, call it "prog", this way: "VAR=/home/dir/ prog".

MensaWater 06-19-2007 03:01 PM

export command is built into bash and ksh. If you are using another shell (e.g. csh or tcsh) it might not be. Variable assignments in other shells are done differently. For example in the original Bourne shell (sh) you had to do two steps:
VAR=value
export VAR
(or VAR=value;export VAR - the semicolon makes it execute the second part of the line after the first part as if you had typed two lines.)

Type "ps" without any options - this should show you what shell you are running.

If it shows "sh" instead of bash or ksh then type "which sh" - this will show you where it found the "sh" command (e.g. /bin/sh).

Type "ls -l <path-to-shell>" where path to shell is what you found in the prior step. Look to see if /bin/sh is a link (will show a right arrow pointing to another file) to something else. Someone recently posted that they were linked to tcsh.

Nylex 06-19-2007 03:12 PM

You use "setenv VARIABLE value" in C shell.

jschiwal 06-19-2007 03:17 PM

You could just assign the environmental variable in your ~/.profile script. Here is an example from mine:
Code:

# Most applications support several languages for their output.
# To make use of this feature, simply uncomment one of the lines below or
# add your own one (see /usr/share/locale/locale.alias for more codes)
#
#export LANG=de_DE.UTF-8        # uncomment this line for German output
#export LANG=fr_FR.UTF-8        # uncomment this line for French output
#export LANG=es_ES.UTF-8        # uncomment this line for Spanish output

Removing the "#" character would redefine LANG. The ~/.profile script is sourced when you log in.

yuan13452 06-19-2007 03:30 PM

I find out I am in C shell,
and tried:"setenv VARIABLE value"
It worked

Thanks a lot

nx5000 06-19-2007 03:34 PM

You can also know which shell you are running by typing
echo $0

There is a key combination that displays the bash version but I can't remember it. If somebody knows it, just shout.

UhhMaybe 09-03-2007 05:23 PM

http://en.wikipedia.org/wiki/Command_line_completion ...try here for the CLI steps to resolve the scripts/line resolve for YOUR files. Good luck to YOU.


All times are GMT -5. The time now is 12:44 PM.