Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-19-2007, 02:50 PM   #1
LQ Newbie
Registered: Jun 2007
Posts: 2

Rep: Reputation: 0
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?

Old 06-19-2007, 03:01 PM   #2
Registered: Feb 2004
Location: Waimanalo, HI
Distribution: Slackware 10, Fedora 6
Posts: 308

Rep: Reputation: 30
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".
Old 06-19-2007, 03:01 PM   #3
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,986
Blog Entries: 14

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
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:
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.
Old 06-19-2007, 03:12 PM   #4
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You use "setenv VARIABLE value" in C shell.
Old 06-19-2007, 03:17 PM   #5
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
You could just assign the environmental variable in your ~/.profile script. Here is an example from mine:
# 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.
Old 06-19-2007, 03:30 PM   #6
LQ Newbie
Registered: Jun 2007
Posts: 2

Original Poster
Rep: Reputation: 0
I find out I am in C shell,
and tried:"setenv VARIABLE value"
It worked

Thanks a lot
Old 06-19-2007, 03:34 PM   #7
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
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.
Old 09-03-2007, 05:23 PM   #8
Registered: Jul 2004
Location: Salt Lake City, Utah
Distribution: Absolute 12.0 Studio 64 1.3.0
Posts: 470

Rep: Reputation: 30
Cool ...try here for the CLI steps to resolve the scripts/line resolve for YOUR files. Good luck to YOU.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
can't set environment variable baosheng Linux - Software 3 04-03-2007 01:53 AM
How to set an environment variable royeo Linux - Newbie 1 12-01-2006 12:59 AM
set environment variable Jongi Linux - Newbie 7 03-01-2004 04:34 AM
how to set CC environment variable General 2 12-18-2001 01:02 AM
how do you set the environment variable CC? Linux - General 0 12-17-2001 09:17 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration