Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Shell script
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Advantages and disadvantages== Perhaps the biggest advantage 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. 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. On the other hand, shell scripting is prone to costly errors. Inadvertent typing errors such as <code>[[rm (Unix)|rm]] -rf * /</code> (instead of the intended <code>rm -rf */</code>) 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's [[root directory]]. Similar problems can transform <code>[[cp (Unix)|cp]]</code> and <code>[[mv (Unix)|mv]]</code> into dangerous weapons, and misuse of the <code>></code> redirect can delete the contents of a file. This is made more problematic by the fact that many UNIX commands differ in name by only one letter: <code>cp</code>, <code>[[cd (command)|cd]]</code>, <code>[[dd (Unix)|dd]]</code>, <code>[[df (Unix)|df]]</code>, etc. 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 (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. There are also compatibility problems between different platforms. [[Larry Wall]], creator of [[Perl]], famously wrote that "It's easier to port a shell than a shell script."<ref>{{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}}</ref> 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.<ref>{{cite web|url=https://www.ooblick.com/text/CshProgrammingConsideredHarmful.html|title=Csh Programming Considered Harmful|author=Christiansen, Tom}}</ref> 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]]).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)