Bash Shell Script File Examples

This section provides some Tcsh script file examples.

The Bash shell supports executable script files, which are collections of Bash command lines stored in text files. When a script file is executed, all command lines in the script file will be executed in the same order they appear in the file.

Here is a Bash shell script file, f, which uses 3 command programs to print information about the specified file:

# f name
if [ $# -eq 0 ]
      echo "Usage: f name"
if [ ! -a $1 ]
      echo "Error: File $1 does not exist"
echo "File list info:"
ls -l $1 # list file info
echo "Numer of lines:"
wc -1 $1 # count words in this file
echo "File type:"
file $1

Another simple Bash shell script example from that shows you how to use the "case" command in a script file:

until [ "$selection" = "0" ]; do
    echo ""
    echo "PROGRAM MENU"
    echo "1 - display free disk space"
    echo "2 - display free memory"
    echo ""
    echo "0 - exit program"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        1 ) df ;;
        2 ) free ;;
        0 ) exit ;;
        * ) echo "Please enter 1, 2, or 0"

Table of Contents

 About This Book

 1957 - FORTRAN Language Developed by IBM

 1970 - UNIX Operating System Developed by AT&T Bell Labs

 1971 - FTP Protocol Created by Abhay Bhushan

 1972 - C Language Developed by Dennis Ritchie

 1976 - vi Text Editor Developed by Bill Joy

 1977 - Apple II Designed by Steve Jobs and Steve Wozniak

 1977 - The Bourne Shell Developed by Stephen Bourne

 1978 - The C Shell Developed by Bill Joy

1978 - Bash (Bourne-Again Shell) Developed by Brian Fox

 What Is Bash (Bourne-Again Shell)?

 Bash Command Line Examples

Bash Shell Script File Examples

 1979 - The Tcsh (TENEX C Shell) Developed by Ken Greer

 1983 - "Sendmail" Mail Transfer Agent Developed by Eric Allman

 1984 - Macintosh Developed by Apple Inc.

 1984 - X Window System Developed a MIT Team

 1991 - WWW (World Wide Web) Developed by Tim Berners-Lee

 1991 - Gopher Protocol Created by a University of Minnesota Team

 1995 - Java Language Developed by Sun Microsystems

 1995 - PHP: Hypertext Preprocessor Created by Rasmus Lerdorf

 2002 - .NET Framework Developed by Microsoft


 PDF Printing Version