Miscellaneous

  Home arrow Miscellaneous arrow Page 5 - 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 - 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.
    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 5 - Follow our Sitemap