Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - 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 - Language variables and some special cases


    (Page 5 of 5 )

    The default character settings are normally English, however the shell is also capable of "speaking" in French, Spanish, German and so on. To make the shell "speak" a certain language, you need to change the LANG environment variable first. For setting specific local settings like the time and date show method preferred, you need to change the numeric variables that start with the LC_ (LC_ALL, LC_TIME, LC_NUMERIC).

    To see what languages can be set on your system, use the local command. This will list the available char sets that the LANG environment variable can take. This is also the primary variable that can determine the LC ones if these are not defined.

    There are a couple of special variables in the UNIX shell. I will present them in the table below:

    Variable Name

    What it means

    $1,$2, #3, ... $n

    These are the arguments list of a command or shell script

    The $1 will refer to the first argument the $2 to the second and etc

    $0

    The name of the shell scrip/program

    $*

    Contains all the arguments in a single string

    $@

    Like the previous example, but now it creates a string list, and not a single string (useful to iterate through a list)

    $#

    The number of arguments for a shell script/program

    $?

    The result of the last executed program (0 means success, and any other number means failure)

    $$

    The identifier number of the running process (process id)

    $!

    The process id of the last program started by the shell that runs (or ran) in the background

    For example, let there be the alfa.sh script. We start it with the command line:

    ./alfa.sh one two three last

    The $1 is one, $2 is two, $3 is three, $4 is the last inside the script.

    $0 is alfa.sh.

    $* is "one two three last".

    $@ is "one", "two", "three" ,"last".

    $# is equal with four.

    This will be all for today. As usual, I invite you to rate my article and ask for your questions in the blog if you have any. In my next article, I will cover concepts like stream direction, pipes, special devices and more. Therefore, make sure you do not miss it if you want to learn shell programming. Live With Passion!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek