- 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.
- Fichier_de_commande (in french).
2 Overview of Shell Scripts
Acknowledgment: The following definitions are based on Garrels' and various articles from Wikipedia.
2.1 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.
2.2 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.
2.3 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.
2.4 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.
2.5 tcsh or Turbo C shell (Unix)
A superset of the common C shell, enhancing user-friendliness and speed.
2.6 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.
To open a simple command promt (command line interface, CLI) under Windows 7, SHIFT-Click on a directory. You then will see menu item that allows opening a command prompt window for a given directory. Alternatively, type "cmd" in the search box of the start menu.
Shell script 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"
2.7 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.
- You may get Version 1 from here Microsoft (in case the links break, just search for "PowerShell" at Microsoft).
- Version 2 (preview as of sept. 2009).
- documentation for powershell v.2.
Example to help you see and remove a file (e.g. a troyan horse exe)
dir -force (will list hidden stuff too) del -force dell.sdr (will kill the hidden *.sdr file) del -force -recurse tmp (will kill the tmp dir)
2.8 Alternative shells for Windows?
There are several non-Microsoft shell alternatives for cmd.exe and PowerShell. Which one you choose depends on your needs, background or other preferences.
- Unix-like Shells. There are some projects to bring the power of POSIX shells (Unix/BSD/Linux etc) to Windows. Most notably is Cywin. Related to Cygwin shells are the following projects MinGW, Mintty, msysgit, RXVT. As these tools offer a compatibility layer to support non-native components the tools may be to heavy for 'just' a cmd alternative. Cygwin homepage
- Terminals. There are several alternative terminals which gives you better support for the history of commands, improved tab-completion, normal copy and paste etc. These tools can be seen as direct replacements for cmd. Examples:
- Commercial shells. There are advanced commercial products like PowerCMD and Take Command which brings improvements to the terminal, commands and window handling. These options are mostly used in professional environments.
- Window enhancers. These are not really shell replacements, but enhances the shell with a GUI (like tabs). The most used tools are Console2 and ConEmu. Other window enhancers (though not actively developed) are poderosa and GNU screen . There are possibilities to combine windows enhancers with the terminals listed above. Console2 for example has the possibility to select alternative terminals. This gives you powerful shell features together with the ease of window enhancements like tabs.
- GNU tools. These tools are native ports of Unix tools including lots of command line tools like grep 
- ColorConsole. This an all-in-one replacement for CMD with a GUI. The software is developed by Nenad Hrg and also comes as a portable version. 
- Stylish Dosbox. A tool that gives cmd.exe a modern look 
- Automation: If you need to automate tasks on Windows than besides PowerShell there are several other script languages available like Autoit or AutoHotKey. Some multi-platform scripting languages are TCL/TK, Python and Perl. Another option is to script your tasks with a GUI tool like Pretty Flow.
2.9 What more shells do you have ?
On a Linux system type:
- Introductions, comparisons
- Various Flavors
- Bourne shell (Wikipedia)
- Bash (Wikipedia). The default Linux / MacOS X shell.
- cmd.exe (Wikipedia). The Windows shell.
- Windows PowerShell (Wikipedia).
3.2 Resource sites
- Heiner's SHELLdorado. your UNIX shell scripting resource. (Good)