Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - 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 - Quotes in UNIX


    (Page 2 of 5 )

    To illustrate this  better I will first present the echo command. The command is simple, but still very useful. It will print back whatever string you throw at it as arguments. The rule is to take the first argument, add a space to it, add the second argument, and add a space to it and so on. Add to the end a new line character and print it in the output. In the end, every argument will be split from the rest by exactly one space.

    echo This is a message

     

    This is a message

    The echo command has two notable options. Adding the -n will let no new line character be added to the end. The -e will allow the interpreting the following special characters inside the arguments: 

    a => bell

    b => delete a character backwards (backspace)

    c => don't print out new line character

    f => throw page

    n => new line

    r => carriage return

    t => horizontal tab

    v => vertical tab

    => backslash

    nnn => The octal ASCI code of the character

    xnn => The hexadecimal ASCI code of the character 

    Now let us return to the quotes. There are three types, as follows: " ' `. The first is the double quote ("). We use this to define strings. With the help of these, we can delimit what is a string. 

    echo "alfa beta" omega

    The upper command will contain only arguments. The "alfa beta" will form a single string, as a single argument. The shell will treat it as a simple string and will not use inside-the-shell meta-characters, like the space that delimits arguments. This is a good way to insert more than one space, for example, inside a string. However, the shell will still change the variables with their values. 

    echo "$color hearth"

    Will echo back to the terminal: 

    red hearth

    Sometimes you do not want this. Maybe you really want to print the $ sign. In this case you can use the single quite ('). You may also know this as the forward tick. What you surround with this will lose all of its meta-character meaning, and the shell will make no changes to it.  

    echo 'I am rich $Color $$*'

    Will echo back just that: 

    I am rich $Color $$*

    The third used quote mark is the back tick (`). This is used to store command outputs in variables. The example below will give you a taste of it; however, I will cover it in more detail in a future article.  

    color='echo red'

    This will store, inside the variable, the return string of the command between the quotes; for now, that is the word "red." 

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