Miscellaneous

  Home arrow Miscellaneous arrow 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


    (Page 1 of 5 )

    Variables. Sure, you can find a couple of them in your life every day. The fact that your girlfriend shows up at the correct time for the date you arranged last week or if the sun will shine like never before are variables that you know will occur only once you live that moment. However, today we will talk about variables that hold some specific data, and in particular, these variables exist inside the UNIX Shell.

    This article will pick up from where I left off last week in the article about the UNIX Shell (titled "The Shell and UNIX"). Furthermore, you can find more articles here or under my profile. These cover the Shell-UNIX programming question. I've given you some interesting information already about the UNIX Shell, so if you missed it I definitely advise you to go back and read my earlier articles. They will provide you with real support in reading this one and extending your Shell programming knowledge.

    So what do you need to know about variables inside the UNIX Shell? The Shell uses variables to store data and information. Because the universal language that the designers chose for UNIX is text strings, the value and the variable itself will be also a string. The assignment is simple, as you can see below.

    [name of variable]=[the string you assign to the variable]

    For example:

    Color=red

    This will create a variable with the name of Color and with the value of red. The creation of variables is dynamic. They will be created when needed. No definition is required. We can refer to the variable later on by putting a $ sign prior to its name. The shell will then replace the variable with its value on the command line. This why the

    echo $color

    will echo back the red string. If we refer to a variable that does not exist via the $ syntax, it will be created and initialized with an empty string.

    Sometimes we want to add meta-characters to strings. These characters have a special meaning to the shell, and this by default should be replaced by something else, depending on what it is. If this occurs, you can still assign those strings with the help of quotes, as you will see on the following page.

    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 5 - Follow our Sitemap