Computer History Notes - Herong's Tutorial Notes - v3.13, by Herong Yang
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:
#!/bin/bash # f name if [ $# -eq 0 ] then echo "Usage: f name" exit fi if [ ! -a $1 ] then echo "Error: File $1 does not exist" exit fi echo echo "File list info:" ls -l $1 # list file info echo echo "Numer of lines:" wc -1 $1 # count words in this file echo echo "File type:" file $1
Another simple Bash shell script example from http://linuxcommand.org/ that shows you how to use the "case" command in a script file:
#!/bin/bash selection= 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" esac done
Table of Contents
2002 - .NET Framework Developed by Microsoft
1995 - PHP: Hypertext Preprocessor Created by Rasmus Lerdorf
1995 - Java Language Developed by Sun Microsystems
1991 - WWW (World Wide Web) Developed by Tim Berners-Lee
1991 - Gopher Protocol Created by a University of Minnesota Team
1984 - X Window System Developed a MIT Team
1984 - Macintosh Developed by Apple Inc.
1983 - "Sendmail" Mail Transfer Agent Developed by Eric Allman
1979 - The Tcsh (TENEX C Shell) Developed by Ken Greer
►1978 - Bash (Bourne-Again Shell) Developed by Brian Fox
What Is Bash (Bourne-Again Shell)
►Bash Shell Script File Examples
1978 - The C Shell Developed by Bill Joy
1977 - The Bourne Shell Developed by Stephen Bourne
1977 - Apple II Designed by Steve Jobs and Steve Wozniak
1976 - vi Text Editor Developed by Bill Joy
1974 - Internet by Vinton Cerf
1972 - C Language Developed by Dennis Ritchie
1971 - FTP Protocol Created by Abhay Bhushan
1970 - UNIX Operating System Developed by AT&T Bell Labs