Linux Environment Variables
How Do I Set and Use Linux Environment Variables?
Environment variables in the bash shell help you in several ways. Certain built-in variables change the shell in ways that make your life a little easier, and you can define other variables to suit your own purposes. Here are some examples of built-in shell variables: · >PS1 defines the shell's command-line prompt.
>· >HOME defines the home directory for a user.
>· >PATH defines a list of directories to search through when looking for a command to execute.
To list the current values of all environment variables, issue the command>
or list a specific variable with the >echo command, prefixing the variable n ame with a dollar sign (the second line shows the result of the >echo command):>
You've already learned how to customize your shell prompt with the PS1 variable. The HOME variable is one you shouldn't mess with, because lots of programs count on it to create or find files in your personal home directory.>
Understanding the Path Variable>
As in DOS, the shell uses the PATH variable to locate a command. PATH contains> a list of dir ectories separated by colons:>
When you enter a command, the shell looks in each of the directories specified in PATH to try to find it. If it can't find the command in any of those directories, you'll see a "Command not found" message.>
If you decide to put your own programs in a bin directory under your home directory, you'll have to modify the path to include that directory, or the system will never find your programs (unless you happen to be in that directory when you enter the command). Here's how to change your PATH variable so it includes your personal bin directory:>
So if PATH was set to >/bin:/usr/bin:/usr/local/bin beforehand, it would now have the value >/bin:/usr/bin:/usr/local/bin:/home/hermie/bin.>
Creating Your Own Shell Variables>
If you are a programmer, you'll find it handy to create your own shell variables. First issue the command>
and then, regardless of what directory you are in, you can issue>
to pop over quickly to the directory containing the source code for that way-cool spew program you're developing. (The >cd command means "change directory.")>
A variable assignment like this will work just fine, but its scope (visibility) is limited to the current shell. If you launch a program or enter another shell, that child task will not know about your environment variables unless you export them first. >
Unless you know for sure that an environment variable will have meaning only in the current shell, it's a good idea to always use >export when creating variables to ensure they will be global in scope--for example,>
export PS1="\u \$ "
And be sure to add these commands to your >.profile file so you won't have to retype them eac h time you log in.>
Comments - most recent first
(Please feel free to answer questions posted by others!)
would like to customize the from to reflect only the mailing account name.
I am beginner in linux. I am trying to install OpenFOAM on Redhat linux 5.1. I have to set environment variables for this the installation page on web shows this instructions.
if running bash or ksh (if in doubt type echo $SHELL), source the etc/bashrc file by adding the following line to the end of your $HOME/.bashrc file:
then type “source $HOME/.bashrc” in the current terminal window
if running tcsh or csh, source the etc/cshrc file by adding the following line to the end of your $HOME/.cshrc file:
then type “source $HOME/.cshrc” in the current terminal window
while doing so i am getting the following out put
root@localhost etc]# source $HOME/.cshrc
alias rm='rm -i'
bash: alias: rm -i: not found
alias cp='cp -i'
bash: alias: cp -i: not found
alias mv='mv -i'
bash: alias: mv -i: not found
can you please guide me, what is the problem and solution for this.
Thank you in advance,
Firstly could someone explain what this does (I assume its just away of cat-ing a load of sql into a variable but not sure what the symbols actually do)-
cat -<<-!! > $SQL
I know that in linux if you are echoing a command into isql that you have to use echo -e. Is there something similar when using cat?
echo -e "select @@servername\ngo" | isql -U$USERNAME -S$server -P$password
and the PATH environmental variable
I would like to view my faxes before I send them in eFax - Ubuntu Linux
How to solve this problem?
./run_w: java: 0403-006 Execute permission denied.
i have set the permissions.
help me ..
Thanks in advance
I created a shell program and tried to export veriables such as classpath or path . However when the shell is completed and control comes back to prompt . If I see same variable they show no values . which means I am not able to set the varibales for the session throough a shell program. can somebody help
when we export any variable that is valid to that particular session. If we switch to other user from that session have to export that variable again. So If want to export the variable in the start up have to include in the start up scripts or profile.
in one terminal window and it works in the same window:
Just the same as when I leave out the export.
Now I open a second window and do
and I get a blank line - just the same as I when I leave out the "export".
So what is the export for - again- please?
Is it only for the files in profile.d ??
Just wanted to find information regarding profile for root in linux and SUN. I understand the concept of .profile however I find that in a recent upgrade to SUN OS 10 the PS and PATH variables
@rem BATCH FILE
if NOT "%1"=="" set dstFolderPath=%1%alfresco\tomcat\webapps\
@rem * Copy from source to destination including subdirs and hidden
@rem * File
RENAME %dstFolderPath%webapps\alfresco\images\logo\AlfrescoFadedBG.png AlfrescoFadedBG_org.png
RENAME %dstFolderPath%webapps\alfresco\images\logo\AlfrescoLogo32.png AlfrescoLogo32_org.png
RENAME %dstFolderPath%webapps\alfresco\images\logo\AlfrescoLogo200.png AlfrescoLogo200_org.png
RENAME %dstFolderPath%webapps\alfresco\jsp\parts\titlebar.jsp titlebar_org.jsp
copy /Y %srcFolderPath%owc.jar %dstFolderPath%webapps\alfresco\WEB-INF\lib\
copy /Y %srcFolderPath%owf.jar %dstFolderPath%webapps\alfresco\WEB-INF\lib\
copy /Y %srcFolderPath%owapp.jar %dstFolderPath%webapps\alfresco\WEB-INF\lib\
copy /Y %srcFolderPath%ags.jar %dstFolderPath%webapps\alfresco\WEB-INF\lib\
copy /Y %srcFolderPath%titlebar.jsp %dstFolderPath%webapps\alfresco\jsp\parts\
copy /Y %srcFolderPath%ow\*.* %dstFolderPath%shared\classes\alfresco\extension\ow\*.*
copy /Y %srcFolderPath%extension\*.* %dstFolderPath%webapps\alfresco\jsp\extension\*.*
copy /Y %srcFolderPath%AlfrescoFadedBG.png %dstFolderPath%webapps\alfresco\images\logo\
copy /Y %srcFolderPath%AlfrescoLogo32.png %dstFolderPath%webapps\alfresco\images\logo\
copy /Y %srcFolderPath%AlfrescoLogo200.png %dstFolderPath%webapps\alfresco\images\logo\
"Could not launch Adobe Reader 9.4. Please make sure it exists in PATH variable in the environment. If the problem persists, please reinstall the application."
Kindly let me know how do I check whether the reader exists in path variable.
then press Enter to put that command in.
to see folders and files. Sometimes, in some unix they show folders in blue and regular files in white. When you press ls and then Enter, you are already in a folder. The top folder that has all folders is called /
If you want to move into a folder type
then press Enter. Press ls again and you see different folders and files. Some files have a . in front of them, but you don't see them when you press ls, even if they are in the folder you are in. When a . is in front of a file, like a file called .bash then that makes it hidden. use ls -a to see those files. All folders have a file called .. and a file called .
.. means the folder above you, so type cd .. and then Enter to go up a folder. To see which folder you are in type pwd.
i m new in unix users but want to know about unix more if you tell me about it. Please help me to work with unix...
I am installing a software in the linux system of Centos, and need to add the following lines to .bashrc file. But I guess there is something wrong with it, cause the software did not work. Could anyone tell me what's wrong with these lines? Many thanks.
I'm trying to install GloMoSim
one of the steps is to create .bashrc file and include the following:
my question is:
how can I access to the file and include these lines??
Is there an environment variable which one can set to control the printing either in bold or raw ascii in CentoS ? If so how would one go about it ?
xxx@xxxx:widget$ export widget=`pwd`
xxx@xxxx:widget$ cd \$widget
bash: cd: $widget: No such file or directory
lets say I typed cd $wid [tab], it auto completes to \$widget, so I have to type the whole word.
Does anyone know how to configure the shell, if I have to use double quotes or something else to avoid getting the backslash at the beginning of the variable??
2)how to set environmental variable in php.
app=$1 # script is run with 1 parameter which #is the environment variable to use e.g.
# CABLAPP is the environment variable so I now #want to say
cd $app # which needs to expand $app to $CABLAPP
#I've tried adding $ to the contents of the variable which i can do, but still doesn't perform the cd command correctly .. how do you extract the contents of a variable to use it as an enviroment variable ?
Could you please show me how to do it properly. Thanks.
One particular prog I am trying to install is pokerth's SVN version which I have downloaded, but there is in the directions:
1. Type "cd path/to/the/sources". Then do for example "/usr/qt/4/bin/qmake pokerth.pro" to configure the makefile for your system.
Pay attention that the QTDIR environment varialbe points to Qt4 not Qt3. For example QTDIR=/usr/qt/4.
You can set this variable typing: "export QTDIR=/usr/qt/4"
I have tried time and time again to install this and the environmental variable confuses me to no end. In the above where does QTDIR go? I've tried everything I can think to try and still it always tells me unable to create the make file.. I have QT4 installed and all the dependencies. Does the env variable command go in the same line as the line, /usr/qt/4/bin/qmake pokerth.pro and if so where and how? If not then how do I set it?
I've been using linux for quite some time and this issue, the env var has ALWAYS gotten my brain tied up in knots where I have to relearn this every time...
CSH: setenv name value
BASH: export name=value
CSH: unsetenv name
BASH: unset name
when i do this it says 'setenv command not found'
wat do i do now?? i am working with linux and am new to it...... thanks in advance
but is there a way to change the GUI terminal prompt too??
I'm running lucid-rc on virtual box although i dont think that should be the problem, I'll try it with an older distro....thanks for the great site though i'm learning a lot ...:-)
How can I see vars I create in a shell across other shells?
cp /etc/php.ini /etc/php.ini0
Next, what changes are you trying to make?
Sadly, each time I've modified the file, I've had to install EVERYTHING again: UBUNTU, and all the applications I'm using.
I know how to make temporal changes to environment variables, but I can't find the way to make system-wide changes.
I NEED HELP!!!!!!!!!!!!!!!
could you inform me please what is with the backslash from first line in relation with slash from the second one.?
NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.