Shell script: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
 
Line 2: Line 2:
== Definition ==
== Definition ==


A shell program executes commands that a user directly types or that are read from a file (the shell script).
* 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 ([http://en.wikipedia.org/wiki/Shell_script Wikipedia], retrieved 14:16, 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:
An educational technologist should know some shell scripting for the following reasons:
Line 8: Line 10:
# Some tools that may be useful (e.g. the most powerful XSLT processors) also may need a script to be launched.
# 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.
# 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:
* [[:fr:Fichier_de_commande Fichier_de_commande]] (in french).


== Overview of Shell Scripts ==
== Overview of Shell Scripts ==
Line 24: Line 29:
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. 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,
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 ===
=== csh or C shell ===
Line 33: Line 40:


A superset of the common C shell, enhancing user-friendliness and speed.
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
Exemple 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 ''jedit.bat'' to launch jedit
start javaw.exe -jar "c:\program files\jEdit\jedit.jar"
   
   
=== What shells do you have ===
=== What shells do you have ? ===


On a linux system type:
On a linux system type:
Line 42: Line 61:
* Usually you only have cmd.exe
* Usually you only have cmd.exe
* Some people however, install  
* Some people however, install  
== Unix CSH ==
== MS Windows ==


== Links ==
== Links ==
Line 70: Line 85:


; Bash
; Bash
* [http://steve-parker.org/sh/sh.shtml Steve's Bourne / Bash shell scripting tutorial]
* [http://steve-parker.org/sh/sh.shtml Bourne / Bash shell scripting tutorial] by Steve Parker
* [http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html Bash Guide for Beginners] by Machtelt Garrels.
* [http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html Bash Guide for Beginners] by Machtelt Garrels.




[[Category: Technologies]]
[[Category: Technologies]]

Revision as of 14:16, 3 August 2007

Draft

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:16, 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:

  1. 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.
  2. Some tools that may be useful (e.g. the most powerful XSLT processors) also may need a script to be launched.
  3. 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:

Overview of Shell Scripts

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

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

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

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 tsch.

tcsh or Turbo C shell

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

Exemple 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 jedit.bat to launch jedit

start javaw.exe -jar "c:\program files\jEdit\jedit.jar"

What shells do you have ?

On a linux system type:

cat /etc/shells

On Windows XP:

  • Usually you only have cmd.exe
  • Some people however, install

Links

Overviews

Introductions, comparisons
Various Flavors
  • Bourne shell (Wikipedia)
  • Bash (Wikipedia). The default Linux / MacOS X shell.
  • cmd.exe (Wikipedia). The Windows shell.

Resource sites

Tutorials

Bash