Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - The Shell and UNIX
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

The Shell and UNIX
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-04-08

    Table of Contents:
  • The Shell and UNIX
  • Shell Programs
  • Shell Commands
  • Command execution

  • 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


    The Shell and UNIX - Shell Programs


    (Page 2 of 4 )

     

    A Shell program file (also known as shell script) is a simple file containing text. The shell will interpret this line by line. Every line will be a different command, just as you would have entered one command after another on the command line of a terminal. The shell will not go ahead until one of the lines is completed, if you do not specifically tell it to do so.  

    The syntax of a command line, as we learned in a previous article titled The Terminal in UNIX, obeys the following sequence: 

    [Command name] [Options] [Arguments] 

    The comment character is the # (hash mark). Nothing after this character in the current line will be interpreted. For example:

     

    #Here we will sort the file alfa.txt

    sort alfa.txt

     

    The first line of a shell script is special. Here we can specify with what interpreter we would like to execute the script. This happens by starting the first line with a comment and an exclamation mark followed by the interpreter we would like to use. For example, let us write a simple script that will display the output "Live with Passion." We will create a file with the name LWP.sh and enter within it the following lines: 

    #!/bin/bash

    echo Live with Passion

    There should be no space between the exclamation mark and the full path to the interpreter. We can run the script in two ways. First, we can just give it to the bash as argument.  

    bash LWP.sh

    When we do, we get this result: 

    Live With Passion

    Another option is to set the execute parameter to on for using chmod. You can read about this in the article titled Rights Management System in UNIX if you missed it. Now we will refer to the file as follows: 

    /LWP.sh

    The output should be the same. The latter example will figure out what interpreter to use with the help of the first line. Therefore, the execution is in fact the creation of a new shell that will get as input the new file. This will link its output to the output of the current shell (terminal), and as you can see, the results. If for some reason the first line is missing, the shell will try to use the default interpreter that lies in the environment variable $SHELL. 

    More Miscellaneous Articles
    More By Gabor Bernat


     

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