<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki1463/index.php?action=history&amp;feed=atom&amp;title=Shell_script</id>
	<title>Shell script - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki1463/index.php?action=history&amp;feed=atom&amp;title=Shell_script"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki1463/index.php?title=Shell_script&amp;action=history"/>
	<updated>2026-12-01T04:20:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.3</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki1463/index.php?title=Shell_script&amp;diff=18886&amp;oldid=prev</id>
		<title>imported&gt;BiblioGator: /* Bourne family */ bare link citation fixed</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki1463/index.php?title=Shell_script&amp;diff=18886&amp;oldid=prev"/>
		<updated>2026-09-08T13:17:58Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Bourne family: &lt;/span&gt; bare link citation fixed&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{short description|Script written for an operating system shell}}&lt;br /&gt;
{{about|scripting in Unix-like systems|scripting in other systems|category:Scripting languages}}&lt;br /&gt;
[[File:FreeBSD 10 vi RC Firewall.png|thumb|Editing a [[FreeBSD]] shell script for configuring [[ipfirewall]] ]]&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;shell script&amp;#039;&amp;#039;&amp;#039; is a [[computer program]] designed to be run by a [[Unix shell]], a [[command-line interpreter]].&amp;lt;ref&amp;gt;&lt;br /&gt;
{{ cite book&lt;br /&gt;
 | author-link  = Brian Kernighan&lt;br /&gt;
 | author2-link = Rob Pike&lt;br /&gt;
 | chapter      = 3. Using the Shell&lt;br /&gt;
 | first1       = Brian W.&lt;br /&gt;
 | first2       = Rob&lt;br /&gt;
 | isbn         = 0-13-937699-2&lt;br /&gt;
 | last1        = Kernighan&lt;br /&gt;
 | last2        = Pike&lt;br /&gt;
 | quote        = The shell is actually a programming language: it has variables, loops, decision-making, and so on.&lt;br /&gt;
 | page         = 94&lt;br /&gt;
 | publisher    = Prentice Hall, Inc.&lt;br /&gt;
 | title        = The UNIX Programming Environment&lt;br /&gt;
 | year         = 1984&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
The various dialects of shell scripts are considered to be [[command language]]s. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup or logging, is called a &amp;#039;&amp;#039;&amp;#039;wrapper&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The term is also used more generally to mean the automated mode of running an operating system shell. Different [[operating system]]s each use a particular name for these functions.  All Unix-like systems include at least one [[POSIX]] shell, typically either [[Bash (Unix shell)|bash]] or the [[zsh]] compatibility mode.&amp;lt;ref&amp;gt;{{cite book|title=Classic Shell Scripting|author=Arnold Robbins and Nelson H.F. Beebe|year=2005|publisher=O&amp;#039;Reilly Media|isbn=978-0-596-00595-5|page=5}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Capabilities==&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
[[Comment (computer programming)|Comments]] are ignored by the shell. They typically begin with the hash symbol (&amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt;), and continue until the end of the line.&amp;lt;ref name=&amp;quot;Pro_Bash_Programming&amp;quot;&amp;gt;{{cite book|last=Johnson|first=Chris|date=2009|url=https://books.google.com/books?id=NJmhi6T0nGMC&amp;amp;q=comment|title=Pro Bash Programming: Scripting the Linux Shell|publisher=Apress|access-date=September 27, 2019|isbn=9781430219989}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Configurable choice of scripting language===&lt;br /&gt;
&lt;br /&gt;
The [[Shebang (Unix)|shebang]], or hash-bang, is a special kind of comment which the system uses to determine what interpreter to use to execute the file. The shebang must be the first line of the file, and start with &amp;quot;&amp;lt;code&amp;gt;#!&amp;lt;/code&amp;gt;&amp;quot;.&amp;lt;ref name=Pro_Bash_Programming /&amp;gt; In Unix-like operating systems, the characters following the &amp;quot;&amp;lt;code&amp;gt;#!&amp;lt;/code&amp;gt;&amp;quot; prefix are interpreted as a path to an executable program that will interpret the script.&amp;lt;ref&amp;gt;{{Cite web|url=https://linux.die.net/man/3/execve|title=exec(3p) – POSIX Programmer&amp;#039;s Manual|access-date=2020-07-24}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Shortcuts===&lt;br /&gt;
A shell script can provide a convenient variation of a system command where special environment settings, command options, or post-processing apply automatically, but in a way that allows the new script to still act as a fully normal [[Unix command]].&lt;br /&gt;
&lt;br /&gt;
One example would be to create a version of [[ls]], the command to list files, giving it a shorter command name of &amp;lt;code&amp;gt;l&amp;lt;/code&amp;gt;, which would be normally saved in a user&amp;#039;s &amp;lt;code&amp;gt;bin&amp;lt;/code&amp;gt; directory as &amp;lt;code&amp;gt;/home/&amp;#039;&amp;#039;username&amp;#039;&amp;#039;/bin/l&amp;lt;/code&amp;gt;, and a default set of command options pre-supplied.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
LC_COLLATE=C ls -FCas &amp;quot;$@&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, the first line uses a [[#Configurable choice of scripting language|shebang]] to indicate which interpreter should execute the rest of the script, and the second line makes a listing with options for file format indicators, columns, all files (none omitted), and a size in blocks. The &amp;lt;code&amp;gt;LC_COLLATE=C&amp;lt;/code&amp;gt; sets the default collation order to not fold upper and lower case together, not intermix [[dotfile]]s with normal filenames as a side effect of ignoring punctuation in the names (dotfiles are usually only shown if an option like &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; is used), and the &amp;lt;code&amp;gt;&amp;quot;$@&amp;quot;&amp;lt;/code&amp;gt; causes any parameters given to &amp;lt;code&amp;gt;l&amp;lt;/code&amp;gt; to pass through as parameters to ls, so that all of the normal options and other [[programming language syntax|syntax]] known to ls can still be used.&lt;br /&gt;
&lt;br /&gt;
The user could then simply use &amp;lt;code&amp;gt;l&amp;lt;/code&amp;gt; for the most commonly used short listing.&lt;br /&gt;
&lt;br /&gt;
Beyond simply providing a set of default for a command, scripts provide for running multiple commands automatically upon script invocation. This one, &amp;lt;span style=&amp;quot;font-family:courier&amp;quot;&amp;gt;ll&amp;lt;/span&amp;gt;, merely clears the terminal of all other text before running a listing command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
clear&lt;br /&gt;
ls -al &amp;quot;$@&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As in the prior example, this &amp;lt;span style=&amp;quot;font-family:courier&amp;quot;&amp;gt;ls -al&amp;lt;/span&amp;gt; invocation lists the files and directories that are in the directory from which the script is being run, or any directories given after &amp;lt;span style=&amp;quot;font-family:courier&amp;quot;&amp;gt;ll&amp;lt;/span&amp;gt; on the command line, which are automatically substituted in for the &amp;lt;span style=&amp;quot;font-family:courier&amp;quot;&amp;gt;&amp;quot;$@&amp;quot;&amp;lt;/span&amp;gt;. The &amp;lt;span style=&amp;quot;font-family:courier&amp;quot;&amp;gt;-la&amp;lt;/span&amp;gt; command options here cause &amp;quot;all&amp;quot; directory contents to be shown in &amp;quot;long&amp;quot; format.&lt;br /&gt;
&lt;br /&gt;
===Batch jobs===&lt;br /&gt;
Shell scripts allow several commands that would be entered manually at a command-line interface to be executed automatically, and without having to wait for a user to trigger each stage of the sequence. For example, in a directory with three C source code files, rather than manually running the four commands required to build the final program from them, one could instead create a script for [[POSIX]]-compliant shells, here named &amp;lt;code&amp;gt;build&amp;lt;/code&amp;gt; and kept in the directory with them, which would compile them automatically:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
echo &amp;#039;compiling...&amp;#039;&lt;br /&gt;
cc -c foo.c&lt;br /&gt;
cc -c bar.c&lt;br /&gt;
cc -c qux.c&lt;br /&gt;
cc -o myprog foo.o bar.o qux.o&lt;br /&gt;
echo &amp;#039;done.&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script would allow a user to save the file being edited, pause the editor, and then just run &amp;lt;code&amp;gt;./build&amp;lt;/code&amp;gt; to create the updated program, test it, and then return to the editor. Since the 1980s or so, however, scripts of this type have been replaced with utilities like [[make (software)|make]] which are specialized for building programs.&lt;br /&gt;
&lt;br /&gt;
===Generalization===&lt;br /&gt;
Simple batch jobs are not unusual for isolated tasks, but using shell loops, tests, and variables provides much more flexibility to users. A POSIX sh script to convert JPEG images to PNG images, where the image names are provided on the command-line—possibly via wildcards—instead of each being listed within the script, can be created with this file, typically saved in a file like &amp;lt;code&amp;gt;/home/&amp;#039;&amp;#039;username&amp;#039;&amp;#039;/bin/jpg2png&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# set $img to each of the jpgs in the command arguments&lt;br /&gt;
for img in &amp;quot;$@&amp;quot;; do       # for each given image...&lt;br /&gt;
    # use ${img%.jpg} to get $img w/o the .jpg&lt;br /&gt;
    png=${img%.jpg}.png   # filename for successful PNG &lt;br /&gt;
    tmp=tmp.png           # filename before sure it worked&lt;br /&gt;
    echo &amp;quot;converting &amp;#039;$img&amp;#039;...&amp;quot;&lt;br /&gt;
    # Use ImageMagick&amp;#039;s &amp;quot;convert&amp;quot; to write our new PNG&lt;br /&gt;
    # image into our $tmp file - which may fail!&lt;br /&gt;
    if convert &amp;quot;$img&amp;quot; &amp;quot;$tmp&amp;quot; ; then  # if it works...&lt;br /&gt;
        # convert worked (since we&amp;#039;re in here)&lt;br /&gt;
        # (this script assumes &amp;quot;mv&amp;quot; always succeeds)&lt;br /&gt;
        mv &amp;quot;$tmp&amp;quot; &amp;quot;$png&amp;quot;   # rename tmp file to target png&lt;br /&gt;
        echo &amp;quot;converted $jpg to $png&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
        # convert failed (since we&amp;#039;re in here)&lt;br /&gt;
        # tell the user about it&lt;br /&gt;
        echo &amp;quot;conversion to $png failed, result in $tmp&amp;quot;&lt;br /&gt;
        exit 1   # exit, the 1 indicates an error&lt;br /&gt;
    fi           # the end of the &amp;quot;if&amp;quot; test construct&lt;br /&gt;
done             # the end of the &amp;quot;for&amp;quot; loop&lt;br /&gt;
echo &amp;#039;all conversions successful&amp;#039;&lt;br /&gt;
# now the script exits with 0 (default) showing success&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;jpg2png&amp;lt;/code&amp;gt; command can then be run on an entire directory full of JPEG images with just &amp;lt;code&amp;gt;/home/&amp;#039;&amp;#039;username&amp;#039;&amp;#039;/bin/jpg2png *.jpg&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Programming===&lt;br /&gt;
Many modern shells also supply various features usually found only in more sophisticated [[general-purpose programming language]]s, such as control-flow constructs, variables, [[Comment (computer programming)|comments]], arrays, [[subroutine]]s and so on. With these sorts of features available, it is possible to write reasonably sophisticated applications as shell scripts. However, they are still limited by the fact that most shell languages have little or no support for data typing systems, classes, threading, complex math, and other common full language features, and are also generally much slower than compiled code or interpreted languages written with speed as a performance goal.&lt;br /&gt;
&lt;br /&gt;
The standard Unix tools [[sed]] and [[awk]] provide extra capabilities for shell programming; [[Perl]] can also be embedded in shell scripts as can other scripting languages like [[Tcl (programming language)|Tcl]].&amp;lt;ref&amp;gt;{{cite book|title=Unix Shell Programming|author=Stephen G. Kochan, Patrick H. Wood|publisher=Sams Publishing|year=2003|isbn=9780672324901|page=243}}&amp;lt;/ref&amp;gt; Perl and Tcl come with graphics toolkits as well.&lt;br /&gt;
&lt;br /&gt;
== Typical shell languages ==&lt;br /&gt;
{{Main|Unix shell}}&lt;br /&gt;
&lt;br /&gt;
=== Bourne family ===&lt;br /&gt;
The [[POSIX]] standard shell language &amp;quot;&amp;lt;code&amp;gt;sh&amp;lt;/code&amp;gt;&amp;quot; is based on the original [[Bourne shell]] (&amp;lt;code&amp;gt;sh&amp;lt;/code&amp;gt;). It is no longer in common use, but the following programs implement a language of this family and remain common:&lt;br /&gt;
&lt;br /&gt;
* [[Almquist shell|Almquist shell]] (&amp;lt;code&amp;gt;ash&amp;lt;/code&amp;gt;), Kenneth Almquist&amp;#039;s re-implementation of Bourne.&amp;lt;ref&amp;gt;{{Cite web |title=sh(1) - NetBSD Manual Pages |url=https://man.netbsd.org/NetBSD-10.1/sh.1 |access-date=2026-07-15 |website=man.netbsd.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
** [[BusyBox]], a collection of small programs commonly found on embedded systems, includes a version of &amp;lt;code&amp;gt;ash&amp;lt;/code&amp;gt;, which tends to serve as the &amp;#039;&amp;#039;only&amp;#039;&amp;#039; &amp;lt;code&amp;gt;sh&amp;lt;/code&amp;gt; on such systems.&lt;br /&gt;
** [[Debian Almquist shell]] (&amp;lt;code&amp;gt;dash&amp;lt;/code&amp;gt;), [[Debian]]&amp;#039;s fork of NetBSD ash, intended as a (much) faster replacement of &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; in package-installation scripts.&amp;lt;ref&amp;gt;{{cite book&lt;br /&gt;
| author=Neal Krawetz&lt;br /&gt;
| title=Ubuntu: Powerful Hacks and Customizations&lt;br /&gt;
| year=2011&lt;br /&gt;
| publisher=[[John Wiley &amp;amp; Sons]]&lt;br /&gt;
| pages=178&lt;br /&gt;
| url=https://books.google.com/books?id=h_zclqESvu8C&amp;amp;pg=PT178&lt;br /&gt;
| isbn=9781118080382}}&amp;lt;/ref&amp;gt; Includes some convenience features such as {{code|local}}.&amp;lt;ref name=deb&amp;gt;{{cite web |title=10. Files |url=https://www.debian.org/doc/debian-policy/ch-files.html#scripts |website=Debian Policy Manual v4.5.0.2}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [[Bash (Unix shell)|GNU Bash]] (&amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt;), the POSIX-compatible shell of the GNU project. Includes numerous feature additions, including many from ksh. The default shell on most Linux distributions.&amp;lt;ref&amp;gt;{{Cite web |title=GNU Bash |url=https://www.gnu.org/software/bash/ |website=GNU Operating System}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [[Z shell]] (&amp;lt;code&amp;gt;zsh&amp;lt;/code&amp;gt;), a liberally-licensed shell with many additions. Is not very Bourne-compatible in the default configuration, but includes an {{code|emulate}} command for compatibility with many other shells.&lt;br /&gt;
&lt;br /&gt;
Formerly-popular shells include:&lt;br /&gt;
&lt;br /&gt;
* The original [[Bourne shell]] (&amp;lt;code&amp;gt;sh&amp;lt;/code&amp;gt;), which had many variants under many different licenses and featuring differing additions.&lt;br /&gt;
** [[Old shell]] (&amp;lt;code&amp;gt;osh&amp;lt;/code&amp;gt;), a &amp;quot;port of the standard command interpreter from Sixth Edition UNIX&amp;quot;&amp;lt;ref&amp;gt;{{Cite web|url=https://manned.org/osh/f30afb07|title=osh - manned.org|website=manned.org|access-date=2019-01-16}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [[KornShell]] (&amp;lt;code&amp;gt;ksh&amp;lt;/code&amp;gt;), David Korn&amp;#039;s Bourne-derived shell, a major influence on later shells.&lt;br /&gt;
* pdksh, a [[Public Domain]] clone of ksh.&lt;br /&gt;
&lt;br /&gt;
Bourne shell features some influence from [[ALGOL]], specifically in the choice of flow control: &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;elif&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;else&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;fi&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;case&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;in&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;esac&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;Unix Shells By Example, pp 7-10,&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Other Unix shells ===&lt;br /&gt;
No longer popular but historically noteworthy:&lt;br /&gt;
&lt;br /&gt;
* [[Tenex C Shell]] (&amp;lt;code&amp;gt;tcsh&amp;lt;/code&amp;gt;) and its predecessor the [[C shell]] (&amp;lt;code&amp;gt;csh&amp;lt;/code&amp;gt;)&lt;br /&gt;
* Tcl shell (&amp;lt;code&amp;gt;tclsh&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The C and Tcl shells have flow-control syntax quite similar to that of similarly-named programming languages.&lt;br /&gt;
(The latter is actually based on the Tcl interpreter and provides the full Tcl language.)&lt;br /&gt;
&lt;br /&gt;
Newer non-Bourne-like shells in common use on Unix-like and UNIX systems include:&lt;br /&gt;
* Nushell (&amp;lt;code&amp;gt;nu&amp;lt;/code&amp;gt;)&lt;br /&gt;
* xonsh shell (&amp;lt;code&amp;gt;xonsh&amp;lt;/code&amp;gt;), pronounced &amp;quot;conch&amp;quot;, a [[Python (programming language)|Python]]-based shell. The language is a superset of Python 3.&lt;br /&gt;
* [[Fish shell]] (&amp;lt;code&amp;gt;fish&amp;lt;/code&amp;gt;). Although not POSIX-compatible or Bash-compatible, it draws inspirations from bashisms.&amp;lt;ref&amp;gt;{{Cite web | title=wait_what_ | url=https://waitwhat.sh/blog/the_case_for_fish/ | access-date=2026-09-04 | website=waitwhat.sh}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [[PowerShell]] (&amp;lt;code&amp;gt;pwsh&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
(Nushell, xonch, and PowerShell are cross-platform beyond Unix-likes and UNIX: they also work natively on Windows.)&lt;br /&gt;
&lt;br /&gt;
=== Other command-line shells ===&lt;br /&gt;
Many programming languages feature [[REPL]]s that may be used as shells. Examples include those for [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[C (programming language)|C]], [[Java (programming language)|Java]], [[Perl]], [[Pascal (programming language)|Pascal]], [[Rexx]] etc. The various shells plus tools like [[awk]], [[sed]], [[grep]], and [[BASIC]], [[Lisp (programming language)|Lisp]], [[C (programming language)|C]] and so forth contributed to the [[Perl]] programming language.&amp;lt;ref&amp;gt;{{cite book |last1=Wall |first1=Larry |last2=Christiansen |first2=Tom |last3=Orwant |first3=Jon |title=Programming Perl |edition=5 |publisher=O&amp;#039;Reilly Media |year=2012 |isbn=9781449303587 |page=Preface}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The standard shell of Microsoft Windows is [[cmd.exe]], which has rudimentary scripting capabilities. It is partly compatible with its even simpler predecessor [[COMMAND.COM]].&lt;br /&gt;
&lt;br /&gt;
So called remote shells such as &lt;br /&gt;
&lt;br /&gt;
* a [[Remote Shell]] (&amp;lt;code&amp;gt;rsh&amp;lt;/code&amp;gt;)&lt;br /&gt;
* a [[Secure Shell]] (&amp;lt;code&amp;gt;ssh&amp;lt;/code&amp;gt;)&lt;br /&gt;
are really just tools to run a more complex shell on a remote system and have no &amp;#039;shell&amp;#039; like characteristics themselves.&lt;br /&gt;
&lt;br /&gt;
==Other scripting languages==&lt;br /&gt;
{{Main|Scripting language}}&lt;br /&gt;
&lt;br /&gt;
Many powerful scripting languages, such as Rexx, Python, Perl, and Tcl, have been introduced to address tasks that are too large, complex, or repetitive to be comfortably handled by traditional shell scripts, while avoiding the overhead associated with compiled languages like C or Java.&amp;lt;ref&amp;gt;{{cite book|last=Flanagan|first=David|title=JavaScript: The Definitive Guide|publisher=O&amp;#039;Reilly Media|year=2020|isbn=9781491952023|page=2}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although the distinction between scripting languages and general-purpose high-level programming languages is often debated, scripting languages are typically characterized by their interpreted nature, simplified syntax, and primary use in automating tasks, coordinating system operations, and writing &amp;quot;glue code&amp;quot; between components.&amp;lt;ref&amp;gt;{{cite book|last=Harold|first=Elliotte Rusty|title=Java Network Programming|publisher=O&amp;#039;Reilly Media|year=2013|isbn=9781449365943|page=6}}&amp;lt;/ref&amp;gt; Even when scripting languages such as Python, Rexx, or JavaScript support compilation to bytecode or use [[just-in-time compilation|JIT]] to improve performance, they are still commonly referred to as &amp;quot;scripting languages&amp;quot; due to their historical association with automation, lightweight tooling, and scripting environments rather than standalone application development.&lt;br /&gt;
&lt;br /&gt;
Scripting is a form of [[Computer programming|programming]]. While &amp;quot;scripting&amp;quot; may emphasize lightweight, task-oriented automation, the broader term &amp;quot;programming&amp;quot; encompasses both scripting and software development in compiled or structured languages. As such, scripting involves writing code to instruct a computer to perform specific tasks—meeting the fundamental definition of programming.&amp;lt;ref&amp;gt;{{cite book|last=Lutz|first=Mark|title=Learning Python|edition=5|publisher=O&amp;#039;Reilly Media|year=2013|isbn=9781449355739|page=6|quote=Python is often called a scripting language, but really it’s just a general-purpose programming language that’s also good at scripting. In fact, scripting is just a subset of programming in general.}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Life cycle==&lt;br /&gt;
Shell scripts often serve as an initial stage in software development, and are often subject to conversion later to a different underlying implementation, most commonly being converted to [[Perl]], [[Python (programming language)|Python]], or [[C (programming language)|C]]. The [[interpreter directive]] allows the implementation detail to be fully hidden inside the script, rather than being exposed as a filename extension, and provides for seamless reimplementation in different languages with no impact on end users.&lt;br /&gt;
&lt;br /&gt;
While files with the &amp;quot;.sh&amp;quot; [[file extension]] are usually a shell script of some kind, most shell scripts do not have any filename extension.&amp;lt;ref&amp;gt;{{cite book&lt;br /&gt;
|last1=Robbins |first1=Arnold |last2=Hannah |first2=Elbert |last3=Lamb |first3=Linda&lt;br /&gt;
|url=https://books.google.com/books?id=J5nKVVg5YHAC |title=Learning the vi and Vim Editors&lt;br /&gt;
|date=2008&lt;br /&gt;
|page=205&lt;br /&gt;
|publisher=O&amp;#039;Reilly Media, Inc. |isbn=9781449313258 }}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book&lt;br /&gt;
|last=Easttom |first=Chuck&lt;br /&gt;
|url=https://books.google.com/books?id=zZYLAAAAQBAJ |title=Essential Linux Administration:: A Comprehensive Guide for Beginners&lt;br /&gt;
|date=2012&lt;br /&gt;
|page=228&lt;br /&gt;
|publisher=Course Technology/Cengage Learning&lt;br /&gt;
|isbn=978-1435459571&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book&lt;br /&gt;
| title = Linux Shell Scripting Essentials&lt;br /&gt;
| last = Kumari&lt;br /&gt;
| first = Sinny&lt;br /&gt;
| quote = Rather than using a file extension for shell scripts, it&amp;#039;s preferred to keep a filename without extension and let an interpreter identify the type by looking into shebang(#!).&lt;br /&gt;
| publisher = Packt Publishing Ltd&lt;br /&gt;
| date = November 23, 2015&lt;br /&gt;
| isbn = 9781783552375&lt;br /&gt;
| url = https://books.google.com/books?id=9vCoCwAAQBAJ&amp;amp;q=shell+script+file+extension&amp;amp;pg=PA2&lt;br /&gt;
| access-date = May 7, 2017&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book&lt;br /&gt;
| title = Wicked Cool Shell Scripts, 2nd Edition: 101 Scripts for Linux, OS X and UNIX Systems&lt;br /&gt;
| last1 = Taylor&lt;br /&gt;
| first1 = Dave&lt;br /&gt;
| last2 = Perry&lt;br /&gt;
| first2 = Brandon&lt;br /&gt;
| publisher = No Starch Press&lt;br /&gt;
| date = December 16, 2016&lt;br /&gt;
| isbn = 9781593276027&lt;br /&gt;
| quote = Shell scripts don&amp;#039;t need a special file extension, so leave the extension blank (or you can add the extension .sh if you prefer, but this isn&amp;#039;t required.&lt;br /&gt;
| url = https://books.google.com/books?id=Mpi7DQAAQBAJ&amp;amp;q=shell+script+file+extension&amp;amp;pg=PA5&lt;br /&gt;
| access-date = May 7, 2017&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Advantages and disadvantages==&lt;br /&gt;
One of the biggest advantages of writing a shell script is that the commands and syntax are exactly the same as those directly entered at the command-line. The programmer does not have to switch to a totally different syntax, as they would if the script were written in a different language, or if a compiled language were used.&lt;br /&gt;
&lt;br /&gt;
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 re-run 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.&lt;br /&gt;
&lt;br /&gt;
On the other hand, shell scripting is prone to costly errors. Inadvertent typing errors such as &amp;lt;code&amp;gt;[[rm (Unix)|rm]] -rf * /&amp;lt;/code&amp;gt; (instead of the intended &amp;lt;code&amp;gt;rm -rf */&amp;lt;/code&amp;gt;) are folklore in the Unix community; a single extra space converts the command from one that deletes all subdirectories contained in the current directory, to one which deletes everything from the file system&amp;#039;s [[root directory]].&amp;lt;ref&amp;gt;{{cite book|last=Shotts|first=William|title=The Linux Command Line|publisher=No Starch Press|year=2019|isbn=9781593279523|page=72}}&amp;lt;/ref&amp;gt; Similar problems can transform &amp;lt;code&amp;gt;[[cp (Unix)|cp]]&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;[[mv (Unix)|mv]]&amp;lt;/code&amp;gt; into dangerous weapons, and misuse of the &amp;lt;code&amp;gt;&amp;gt;&amp;lt;/code&amp;gt; redirect can delete the contents of a file.&amp;lt;ref&amp;gt;{{cite book |last1=Albing |first1=Carl |last2=Vossen |first2=JP |last3=Newham |first3=Cameron |title=Bash Cookbook |publisher=O&amp;#039;Reilly Media |year=2007 |isbn=9780596526788 |page=53}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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&amp;#039;s job can be accomplished by setting up a [[Pipeline (computing)|pipeline]] in which efficient [[Filter (software)|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.&lt;br /&gt;
&lt;br /&gt;
There are also compatibility problems between different platforms. [[Larry Wall]], creator of [[Perl]], famously wrote that &amp;quot;It&amp;#039;s easier to port a shell than a shell script&amp;quot;, referring to the inconsistent behavior of command-line programs across systems.&amp;lt;ref&amp;gt;{{cite newsgroup |title=Finding the last arg |author=[[Larry Wall]] |date=January 4, 1991 |newsgroup=comp.unix.shell |url=https://www.tuhs.org/Usenet/comp.unix.shell/1991-January/002464.html |access-date=January 5, 2023}}&amp;lt;/ref&amp;gt; (His specific example would have been fixed by POSIX standardization of &amp;lt;code&amp;gt;[[grep]]&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;ref&amp;gt;{{cite web|url=https://www.ooblick.com/text/CshProgrammingConsideredHarmful.html|title=Csh Programming Considered Harmful|author=Christiansen, Tom}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many disadvantages of using some script languages are caused by design flaws within the [[programming language syntax|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 (programming language)|Scheme]]).&lt;br /&gt;
&lt;br /&gt;
==Interoperability among scripting languages==&lt;br /&gt;
&lt;br /&gt;
Many scripting languages share similar syntax and features due to their adherence to the [[POSIX]] standard, and several shells provide modes to emulate or maintain compatibility with others. This allows scripts written for one shell to often run in another with minimal changes.&lt;br /&gt;
&lt;br /&gt;
For example, [[Bash (Unix shell)|Bash]] supports much of the original [[Bourne shell]] syntax and offers a POSIX-compliant mode to improve portability. However, Bash also includes a number of extensions not found in POSIX, commonly referred to as &amp;#039;&amp;#039;[[Bash (Unix shell)#POSIX mode|bashisms]]&amp;#039;&amp;#039;. While these features enhance scripting capabilities, they may reduce compatibility with other shells like [[Dash (shell)|Dash]] or [[KornShell|ksh]].&lt;br /&gt;
&lt;br /&gt;
A script that uses features specific to a certain shell may use a matching [[shebang (Unix)|shebang]] (&amp;lt;code&amp;gt;#!&amp;lt;/code&amp;gt;) as the first line, so that the operating system will use the specified interpreter (e.g. &amp;lt;code&amp;gt;/bin/bash&amp;lt;/code&amp;gt;) to run the script, though this will not be sufficient when a feature is added to a shell without changing its name, or when one manually runs the script (e.g. &amp;lt;code&amp;gt;sh foo.sh&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
A script can also check which shell it is being ran on and exit before the missing features are used, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
die() { printf &amp;#039;%s\n&amp;#039; &amp;quot;$1&amp;quot; &amp;gt;&amp;amp;2; exit 1; }&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$BASH_VERSINFO&amp;quot; -lt 4 ]; then&lt;br /&gt;
  die &amp;quot;Not bash 4 or above. Need bash 4 or above.&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# This is a bashism, specifically supported only by bash 4.0+.&lt;br /&gt;
declare -A dictionary&lt;br /&gt;
# ... rest of script&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above, the opening lines of the script is written in pure POSIX shell. When a non-bash shell run the script, &amp;lt;code&amp;gt;$BASH_VERSINFO&amp;lt;/code&amp;gt; will not be set; this triggers the test and causes the script to exit before the incompatible line is reached. When a bash version prior to 4.x runs the script, the same test is triggered by numeric comparison (&amp;lt;code&amp;gt;-lt&amp;lt;/code&amp;gt;). ({{code|declare -A}} declares an [[associative array]], a feature new to bash 4.0 and not found on previous versions.)&lt;br /&gt;
&lt;br /&gt;
==Shell scripting on other operating systems==&lt;br /&gt;
&lt;br /&gt;
Interoperability software such as [[Cygwin]], the [[MKS Toolkit]], [[Interix]] (formerly part of Microsoft Windows Services for UNIX), [[Hamilton C shell]], and [[UWIN]] (AT&amp;amp;T Unix for Windows) enables Unix shell programs to run on Windows NT-based systems, though some features may not be fully supported on the older [[MS-DOS]]/[[Windows 95]] platforms. Earlier versions of the MKS Toolkit also provided support for OS/2. &lt;br /&gt;
&lt;br /&gt;
Scripting languages are, by definition, able to be extended. On Unix and other [[POSIX]]-compliant systems, [[awk]] and [[sed]] are used to extend the string and numeric processing ability of shell scripts. [[Tcl (programming language)|Tcl]], Perl, Rexx, and Python have graphics toolkits and can be used to code functions and procedures for shell scripts which pose a speed bottleneck (C, Fortran, assembly language &amp;amp;c are much faster still) and to add functionality not available in the shell language such as sockets and other connectivity functions, heavy-duty text processing, working with numbers if the calling script does not have those abilities, self-writing and self-modifying code, techniques like [[recursion]], direct memory access, various types of [[sorting]] and more, which are difficult or impossible in the main script, and so on. [[Visual Basic for Applications]] and [[VBScript]] can be used to control and communicate with such things as spreadsheets, databases, scriptable programs of all types, telecommunications software, development tools, graphics tools and other software which can be accessed through the [[Component Object Model]].&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Glue code]]&lt;br /&gt;
* [[Interpreter directive]]&lt;br /&gt;
* [[Shebang (Unix)|Shebang symbol (#!)]]&lt;br /&gt;
* [[Unix shell]]s&lt;br /&gt;
* [[PowerShell]]&lt;br /&gt;
* [[Windows Script Host]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
{{wikibooks|Shell Programming}}&lt;br /&gt;
* [http://www.faqs.org/docs/air/tsshell.html &amp;#039;&amp;#039;An Introduction To Shell Programming&amp;#039;&amp;#039; by Greg Goebel]&lt;br /&gt;
* [https://www.shellscript.sh &amp;#039;&amp;#039;UNIX / Linux shell scripting tutorial&amp;#039;&amp;#039; by Steve Parker]&lt;br /&gt;
* [https://developer.apple.com/mac/library/documentation/OpenSource/Conceptual/ShellScripting/ &amp;#039;&amp;#039;Shell Scripting Primer&amp;#039;&amp;#039; (Apple)]&lt;br /&gt;
* [https://www.linux.com/articles/34658 &amp;#039;&amp;#039;What to watch out for when writing portable shell scripts&amp;#039;&amp;#039; by Peter Seebach]&lt;br /&gt;
* [http://freebookcentre.net/UnixCategory/Free-Unix-Shell-Programming-Books-Download.html Free Unix Shell scripting books]&lt;br /&gt;
* [https://help.ubuntu.com/community/Beginners/BashScripting Beginners/BashScripting], Ubuntu Linux&lt;br /&gt;
&lt;br /&gt;
{{Programming languages}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting languages]]&lt;br /&gt;
[[Category:Unix software]]&lt;/div&gt;</summary>
		<author><name>imported&gt;BiblioGator</name></author>
	</entry>
</feed>