A shell script is a script written for the shell, or command line interpreter, of an operating system. "Scripting" redirects here For other uses see Script. In computing a shell is a piece of software that provides an interface for users An operating system (commonly abbreviated OS and O/S) is the software component of a Computer system that is responsible for the management and coordination It is often considered a simple domain-specific programming language. The term domain-specific language ( DSL) has become popular in recent years in Software development to indicate a Programming language or Specification 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 (OS/2, Windows) command line scripts are usually called batch files, but here properties of both are discussed. A Unix shell, is a command line shell that provides the traditional User interface for the Unix Operating system and for Unix-like COMMANDCOM is the filename of the default Operating system shell for DOS Operating systems and the default Command line interpreter DOS, short for "Disk Operating System" is a shorthand term for several closely related Operating systems that dominated the IBM PC compatible market cmdexe is the Command line interpreter on OS/2, Windows CE and on Windows NT -based operating systems (including Windows OS/2 is a computer Operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively Microsoft Windows is a series of Software Operating systems and Graphical user interfaces produced by Microsoft. In DOS, OS/2, and Microsoft Windows, a batch file is a Text file containing a series of commands intended to be executed by the
Many shell script interpreters double as command line interface, such as the various Unix shells, Windows PowerShell or the MS-DOS COMMAND. Windows PowerShell is an extensible command-line shell and associated Scripting language from Microsoft MS-DOS (short for M icro' s' oft D isk O perating S ystem is an Operating system commercialized by Microsoft. COM. Others, such as AppleScript or the graphical Windows Script Host (WScript. AppleScript is a Scripting language devised by Apple Inc, and built into Mac OS. The Microsoft Windows Script Host (originally called Windows Scripting Host, but renamed for the second release is distributed and installed by default on Windows exe), add scripting capability to computing environments without requiring a command line interface. Other examples of programming languages primarily intended for shell scripting include DCL and JCL. A programming language is an Artificial language that can be used to write programs which control the behavior of a machine particularly a Computer. DCL, the DIGITAL Command Language, is the standard command languageadopted by most of the Job Control Language ( JCL) is a Scripting language used on IBM mainframe operating systems to instruct the system on how to run a batch job or
Contents |
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 text files (*. The Bourne shell, or sh, was the default Unix shell of Unix Version 7, and replaced the Thompson shell, whose executable file had the same A text file (sometimes spelled "textfile" is a kind of Computer file that is structured as a sequence of lines. txt) and MP3 files (*. MPEG-1 Audio Layer 3, more commonly referred to as MP3, is a Digital audio encoding format using a form of Lossy data compression mp3) in the working directory to the root directory:
cp *. In Computing, the working directory of a process is a directory of a hierarchical File system, if any dynamically associated with each process In computer File systems the root directory is the first or top-most directory in a hierarchy txt / cp *. mp3 /
This example also demonstrates the use of wildcard characters, a simple way of matching multiple related files ("*" denotes any sequence of characters). For other meanings of 'wild card' see Wild card. The term wildcard character has the following meanings Telecommunication In Most shells implement basic pattern matching capabilities like this, which allow them to perform commands on groups of items with similar names and sometimes parse simple strings of text. In Computer science, pattern matching is the act of checking for the presence of the constituents of a given Pattern.
Although each shell scripting language is different, there are a number of additional features which are often provided. One is a mechanism for manipulating some form of variables, in other words, named values which can be inserted elsewhere in the script at specified locations. A variable (ˈvɛərɪəbl is an Attribute of a physical or an abstract System which may change its Value while it is under Observation. For example, this script copies all . txt and . mp3 files from the current directory to the directory named by the variable "fuzzy":
cp *. txt $fuzzy cp *. mp3 $fuzzy
By changing the value of the variable "fuzzy", the user can specify to where the files are copied. However, rewriting a script to change a variable's definition each time the script is run would be a nuisance, so scripting languages typically also support special variables which provide access to any arguments passed to the script on the command line. For example, $1 through $9 refer to the first nine arguments given to a Bourne shell script, as do %1 through %9 in DOS batch files. Also, a shell's internal variables are often integrated with the operating system's notion of per-process or per-session environment variables. Environment variables are a set of dynamic values that can affect the way running processes will behave on a computer
Another common feature of shell scripting languages is some way of dealing with return codes, which are numbers returned from executed programs to indicate whether they succeeded or failed. In the Bourne shell, for example, the notation a && b means to first execute a, then execute b only if a succeeded.
Many modern shells also supply various features usually found only in more sophisticated general-purpose programming languages, such as control-flow constructs (if, while, goto), mutable variables, comments, subroutines, and so on. The term domain-specific language ( DSL) has become popular in recent years in Software development to indicate a Programming language or Specification In Computer programming, a comment is a Programming language construct used to embed Information in the Source code of a computer program In Computer science, a subroutine ( function, method, procedure, or subprogram) is a portion of code within a larger With these sorts of features available, it is sometimes possible to write reasonably sophisticated applications as shell scripts, although of course the more demanding, complex or large-scale systems will usually require more powerful programming languages. Though the shells are powerful in their way, they have few structuring mechanisms, limited built-in commands, and are generally interpreted relatively slowly.
For tasks that are too large or complex to be comfortably handled with ordinary shell scripts, but for which the advantages of a script are desirable and the development overhead of a full-blown, compiled programming language would be disadvantageous, many powerful scripting languages have been introduced. "Scripting" redirects here For other uses see Script. The specifics of what separates scripting languages from high-level programming languages is a frequent source of debate. In computing a high-level programming language is a Programming language with strong abstraction from the details of the computer
Often, writing a shell script is much quicker than writing the equivalent code in other programming languages. The many advantages include easy program or file selection, quick start, and interactive debugging. A shell script can be used to provide a sequencing and decision-making linkage around existing programs, and for moderately-sized scripts the absence of a compilation step is an advantage. Interpretive running makes it easy to write debugging code into a script and rerun it to detect and fix bugs. Non-expert users can use scripting to tailor the behavior of programs, and shell scripting provides some limited scope for multiprocessing.
On the other hand, shell scripting is prone to costly errors. Inadvertent typing errors such as rm -rf * / (instead of the intended rm -rf */) are folklore in the Unix community; a single extra space converts the command from one that deletes everything in the sub-directories to one which deletes everything - and also tries to delete everything on the root partition. rm (short for remove) is a Unix command used to delete files from a Filesystem. Similar problems can transform cp and mv into dangerous weapons, and misuse of the > redirect can delete the contents of a file. cp is the command entered in a Unix shell to copy a file from one place to another possibly on a different Filesystem. mv (short for m o' v' e is a Unix command that moves one or more files or directories from one place to another This is made more problematic by the fact that many UNIX commands differ in name by only one letter: cp, cn, cd. cd, sometimes also available as chdir ( ch ange dir ectory is a command line command to change the current Working directory
Another significant disadvantage is the slow execution speed and the need to launch a new process for almost every shell command executed. When a script's job can be accomplished by setting up a pipeline in which efficient filter commands perform most of the work, the slowdown is mitigated, but a complex script is typically several orders of magnitude slower than a conventional compiled program that performs an equivalent task. In Computing, a pipeline is a set of data processing elements connected in series so that the output of one element is the input of the next one A filter is a computer program to process a Data stream. Some Operating systems such as Unix are rich with filter programs
There are also compatibility problems between different platforms. Larry Wall, creator of Perl, famously wrote that "It is easier to port a shell than a shell script. Larry Wall (born September 27, 1954) is a Programmer and Author, most widely known for his creation of the Perl Programming "
Similarly, more complex scripts can run into the limitations of the shell scripting language itself; the limits make it difficult to write quality code and extensions by various shells to ameliorate problems with the original shell language can make problems worse. [1]
Many disadvantages of using some script languages are caused by design flaws within the language syntax or implementation, and are not necessarily imposed by the use of a text-based command line; there are a number of shells which use other shell programming languages or even full-fledged languages like Scsh (which uses Scheme). Scsh is a POSIX API layered on top of the Scheme programming language in a manner to make the most of Scheme's capability for scripting Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is