Miscellaneous
  Home arrow Miscellaneous arrow Page 4 - Variables Within the UNIX Shell
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Variables Within the UNIX Shell
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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


     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek