Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - 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 / 5
    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 - 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


     

    MISCELLANEOUS ARTICLES

    - Install Slackware on Your Old PC
    - Firefox Plugins You`re Not Using (and Should...
    - Working with MP3 ID3 Tags in FTP Server Usin...
    - How Switching to Linux Can Make Your Computi...
    - Set Up Your Home Office on Linux: a Guide fo...
    - Putty File Transfer Commands in SSH Protocol
    - Setting Up Ubuntu for Your Home Office
    - Installing Mint Linux
    - Crucial Traits of Awk
    - 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





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