Miscellaneous

  Home arrow Miscellaneous arrow Page 4 - Variables Within the UNIX Shell
MISCELLANEOUS

Variables Within the UNIX Shell
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2009-04-15

    Table of Contents:
  • Variables Within the UNIX Shell
  • Quotes in UNIX
  • The usage of curly braces
  • Environment Variables and the start of the shell
  • Language variables and some special cases

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Variables Within the UNIX Shell - Environment Variables and the start of the shell


    (Page 4 of 5 )

    Besides the variables that you can create, there are collections of variables that describe the environment. These are automatically collected by the shell when you start a terminal (for example), and are written entirely in capital letters. This way, you can differentiate them from your variables, as it is generally advised that you use only lower case letters for your variables. 

    You can use them just like any other variables. You can get a full list of them by using the printenv command. This will list both the environment variable name and its content. The table below describes a few of them:

    Variable Name

    What it means

    Example

    HOSTNAME

    The full domain name of the computer

    mari.sak.com

    TERM

    The type of the terminal

    xterm

    SHELL

    The full path of the shell that is by default used for the current user

    /bin/bash

    USER

    The login name of the user

    gaborj

    MAIL

    The address mail of the user

    /var/spool/mail/gaborj

    PATH

    The path where the shell should look for executable programs / tools

    /bin:/usr/local/bin:.

    PWD

    The current working directory

    /home/gaborj

    EDITOR

    The implicit text editor of the user

    /usr/bin/vim

    LANG

    The used language and character set

    en_US.UTF-8

    HOME

    The home folder of the user

    home/gaborj

    When you start the shell, it will read a couple of configuration files. This will set variables and run programs that will determine how the environment of the shell will look. Between these are files that work for all users, like the /etc/profile or /etc/bashrc. Besides this, there is a corresponding file (.profil, .bash_profile) in the home folder of each user. We use this to make custom settings.

    Modify the environment variables. Set aliases. Task like this should be done here. A .profile and the .bash_profile file will be interpreted at the start of the shell in the given order. We can add a variable to the environment variables with the export command. The child shell I was speaking of will only get the environment variable via inheritance. If you do not know what a child shell is, go back to my previous article and read it.

    For example, we will extend the PATH environment variable with the current directory:

    PATH=$PATH:./

    export Path

    This is what you should add to those configuration files. For settings that should be executed when you close the shell, use the .bash_logout configuration file. Naturally, these file names are for the bash Shell.

    More Miscellaneous Articles
    More By Gabor Bernat

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap