Shell script
Definition
- A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. Usually, shell script refers to scripts written for a Unix shell, while COMMAND.COM (DOS) and cmd.exe (Windows) command line scripts are usually called batch files (Wikipedia, retrieved 14:30, 3 August 2007 (MEST)).
- A shell program executes commands that a user directly types or that are read from a file (the shell script). As an alternative to shell scripts, you can in some cases, use a scripting language like Perl or PhP.
An educational technologist should know some shell scripting for the following reasons:
- Often, educational software is programmed in Java. When these programs are distributed as *.jar files they may not launch properly (even on Windows) and you will have to write a shell script.
- Some tools that may be useful (e.g. the most powerful XSLT processors) also may need a script to be launched.
- To deploy Internet Software it is better to use a Linux system (it's cheaper and slightly safer than windows). To do so, you need a lit bit of scripting knowledge.
See also:
- Fichier_de_commande (in french).
Overview of Shell Scripts
Acknowledgment: The following definitions are based on Garrels' and various articles from Wikipedia.
sh or Bourne Shell
The (almost) original shell still used on UNIX systems and in UNIX-related environments. This is the basic shell, a small program with few features. While this is not the standard shell, it is still available on every Linux system for compatibility with UNIX programs.
ksh or the Korn shell (Unix)
The Korn shell (ksh) is a Unix shell which was developed by David Korn (AT&T Bell Laboratories) in the early 1980s. A superset of the Bourne shell and upwards compatible with the Bourneshell.
bash or Bourne Again shell (Unix)
Bash is the default shell on most Linux systems as well as on Mac OS X and it can be run on most Unix-like operating systems. The Bash command syntax is a superset of the Bourne shell command syntax. The vast majority of Bourne shell scripts can be executed by Bash without modification. Commands that work in sh, also work in bash. However, the reverse is not always the case.
Bash is the default shell on most Linux systems as well as on Mac OS X and it can be run on most Unix-like operating systems. The Bash command syntax is a superset of the Bourne shell command syntax. The vast majority of Bourne shell scripts can be executed by Bash without modification.
Example:
csh or C shell (Unix)
The C shell (csh) is a Unix shell developed by Bill Joy for the BSD Unix system. The syntax of this shell resembles that of the C programming language and therefore popular with C programmers. Today, mostly replaced by tcsh.
tcsh or Turbo C shell (Unix)
A superset of the common C shell, enhancing user-friendliness and speed.
cmd.exe (Windows)
cmd.exe is the command line interpreter on OS/2, Windows CE and on Windows NT-based systems (including Windows 2000, XP, Vista, and Server 2003). It is the analog of COMMAND.COM in MS-DOS and Windows 9x systems, or of the shells used on Unix systems.
These files are either called *.bat or *.cmd
Example file sax.cmd to launch the saxon XSLT processor
java -jar c:\bin\saxon8.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
Example file xquery.cm to launch the saxon XQuery processor (a bit more complicated)
rem set the variable JAVA to the place where the java command is located rem not the case if you just have one Jave that is correctly installed), for example rem set JAVA="c:\Program Files\java\jdk1.5.0\bin\java" set JAVA=java rem modify the following line to set the classpath (saxon.jar) set CP=-cp c:\soft\saxon861b\saxon8.jar %JAVA% %CP% net.sf.saxon.Query %1 %2 %3 %4 %5 %6 %7 %7
Example file jedit.bat to launch jedit
start javaw.exe -jar "c:\program files\jEdit\jedit.jar"
Windows PowerShell
Windows PowerShell, previously Microsoft Shell or MSH (codenamed Monad) is an extensible command line interface (CLI) shell and scripting language product developed by Microsoft based on object-oriented programming and version 2.0 of the .NET Framework. It is available for Windows XP, Windows Server 2003 and Windows Vista and planned for inclusion with Windows Server 2008.
What shells do you have ?
On a Linux system type:
cat /etc/shells
On Windows XP:
- Usually you only have cmd.exe
- On Vista or if you have .net 2.0 you have Windows Power Shell.
- You also may install Unix-compatibility programs like Cywin in order to add Unix-like scripting.
Links
Overviews
- Introductions, comparisons
- Shell Script (Wikipedia)
- Shell (computing) (Wikipedia)
- Comparison of computer shells (Wikipedia).
- Various Flavors
- Bourne shell (Wikipedia)
- Bash (Wikipedia). The default Linux / MacOS X shell.
- cmd.exe (Wikipedia). The Windows shell.
- Windows PowerShell (Wikipedia).
Resource sites
- Heiner's SHELLdorado. your UNIX shell scripting resource. (Good)
Tutorials
- Bash
- Bourne / Bash shell scripting tutorial by Steve Parker
- Bash Guide for Beginners by Machtelt Garrels.