Shell script

A shell script is a script written for the shell, or command interpreter, of an operating system. 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 DOS and Windows command-line scripts are called batch files, but here we discuss properties of both. Bourne shell-derived scripting languages are more commonly used than C shell-derived languages for writing shell scripts.

Many shell script interpreters double as command-line interfaces, such as the Unix shell or the MS-DOS COMMAND.COM. Others, such as AppleScript, add scripting capability to computing environments lacking a command-line interface. Examples of shell script languages include:


In their most basic form, shell scripts allow several commands that would be entered "by hand" at a command-line interface to be executed automatically and rapidly. For example, the following Bourne shell script copies all .txt and .mp3 files in the current directory to the root directory:

 cp *.txt /
 cp *.mp3 /

Although each shell script is different, there are a number of common extensions to this primitive macro capability that script writers find useful. One is environment variables, the ability to predefine certain values which are then inserted in the script at specified locations. For example, this script copies all .txt and .mp3 files from the directory whose name is in the environment variable "fuzzy" to the root:

 cp $fuzzy/*.txt /
 cp $fuzzy/*.mp3 /

Now, by changing the value of the environment variable "fuzzy", the user can affect where the files are copied from. However, changing these every time they run the script is taxing, so most scripting languages predefine certain environment variables referring to arguments passed to the script on the command-line. For example, $1 through $9 refer to the first nine arguments given to the script in Bourne shell, as do %1 through %9 in DOS batch files.

Another popular feature of shell scripts is some way of dealing with return codes, which are numbers returned from executed programs to indicate whether they succeeded or failed. In Bourne shell, for example, a && b is a command to execute a, then execute b only if a succeeded. Batch files use if errorlevel for this purpose.

Most shell scripts also import a selection of features from more sophisticated programming languages, such as control-flow constructs (if, while, goto), mutable variables, comments, subroutines, and so on. Nevertheless, they are rarely adequate for programming of a complex or large-scale system, because they have few structuring mechanisms, limited built-in commands, and are generally interpreted slowly.

For tasks deemed too large or complex to be comfortably handled with shell scripts, programs are often written in scripting languages, such as Perl. However, core system maintenance scripts, which might otherwise be written in such a language, continue to be written as shell scripts, as they cannot always rely on the presence of scripting language engines.

External links


  • Art and Cultures
    • Art (
    • Architecture (
    • Cultures (
    • Music (
    • Musical Instruments (
  • Biographies (
  • Clipart (
  • Geography (
    • Countries of the World (
    • Maps (
    • Flags (
    • Continents (
  • History (
    • Ancient Civilizations (
    • Industrial Revolution (
    • Middle Ages (
    • Prehistory (
    • Renaissance (
    • Timelines (
    • United States (
    • Wars (
    • World History (
  • Human Body (
  • Mathematics (
  • Reference (
  • Science (
    • Animals (
    • Aviation (
    • Dinosaurs (
    • Earth (
    • Inventions (
    • Physical Science (
    • Plants (
    • Scientists (
  • Social Studies (
    • Anthropology (
    • Economics (
    • Government (
    • Religion (
    • Holidays (
  • Space and Astronomy
    • Solar System (
    • Planets (
  • Sports (
  • Timelines (
  • Weather (
  • US States (


  • Home Page (
  • Contact Us (

  • Clip Art (
Personal tools