4

I've been writing scripts for both UNIX and Windows for almost 3 years now. I've always been confused about these two terms, for a while I thought that bash scripts were windows cmd scripts and shell scripts were UNIX scripts, but I've learned that this is not correct. So what is the difference between these two terms: BASH and Shell scripts?

mkmostafa
  • 3,071
  • 2
  • 18
  • 47
  • 2
    A "shell script" is a term describing .. well, "some script" that can be interpreted/run by ["a shell'](https://en.wikipedia.org/wiki/Unix_shell). Normally an ['sh'-derived (Bourne-shell like)](https://en.wikipedia.org/wiki/Bourne_shell) shell. [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) is a specific implementation of a shell and is 'sh'-derived with many features. Technically a "shell script" could be for a different kind of shell; but such are usually rare; or denoted by specifies such as a "batch file" - for a cmd.exe "shell script" - or "powershell". – user2864740 Aug 13 '15 at 23:32
  • 2
    so basically, there are different types of shells and a bash is a type of shells? – mkmostafa Aug 13 '15 at 23:38
  • Yes. That is a fairly good summary. – user2864740 Aug 13 '15 at 23:38
  • You're probably confusing "bash" with "batch" for windows cmd scripts. – glenn jackman Aug 13 '15 at 23:57
  • @glennjackman Nope. I know that batch are the scripts run on windows and they have the extension .bat. I was just asking about the difference between bash and shell :) – mkmostafa Aug 14 '15 at 00:00
  • Worth reading this thread as well [Sh and Bash][1] [1]: http://stackoverflow.com/questions/5725296/difference-between-sh-and-bash – anishjp Aug 14 '15 at 07:11

4 Answers4

9

"Shell script" is generic term for a script that's executed by a shell.

"Bash script" is a more specific term; it refers to a script that's executed by one specific shell, the Bash shell.

A shell is a command interpreter program. It can be used interactively (where the user types commands at a prompt, and the shell executes them), or as an interpreter for a script (where a series of commands are written in a file).

The Bourne shell is one of the older shells on UNIX (not the oldest, but we needn't worry about ancient history). Several other shells have been implemented as replacements for, or extensions of, the Bourne shell.

In particular, GNU Bash is perhaps the most commonly used shell these days. It implements the same features as the Bourne shell, plus a number of extensions.

A Bourne shell script typically starts with "Shebang" line:

#!/bin/sh

A Bash script typically starts with a Shebang that specifies the Bash shell:

#!/bin/bash

and may depend on features implemented by Bash but not by the Bourne shell.

(On some operating systems, /bin/sh might be the same command as /bin/bash.)

Not all Unix shells are based on the Bourne shell. In particular, csh and its derivative tcsh are largely incompatible with the Bourne-derived shells.

Bash has very little to do with Windows cmd scripts, except that both Bash and cmd.exe are both command interpreters.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • so is "cmd" also considered a shell type? and can we say that a "batch" script is a "windows shell script"? – mkmostafa Aug 14 '15 at 00:04
  • 1
    @MohamedKhaled: Yes, `cmd` can be considered a shell. The word "shell" is usually used for Unix shells, but the PowerShell is specific to Windows. – Keith Thompson Aug 14 '15 at 00:06
3

The same way Windows, Linux and MacOSX are operating systems, or Audi, Ford or Chevrolet are cars: windows' cmd.exe, BASH, ZSH, CSH, TCSH, Korn Shell, Bourne Shell… are just different kinds of shells.

Generally speaking, the "shell" is an analogy to design the user interface that enables access to the "core" of a system. So in this case, the shell is the textual interface (also called command line interface aka CLI) used to operate the system.

Now, when you're talking about "shell scripting", it's just using the language developed for the user interface to automatize tasks on that system. There are a few graphical oriented scripting existing (like Office's macros) but most of the time it's about creating a "batch" file (.bat on Dos/Windows) or what in the unix world is being called a "shell script".

here are a few of wikipedia articles to read more about it:

zmo
  • 24,463
  • 4
  • 54
  • 90
  • 1
    if someone could explain why the `-1`? I believe I'm being quite accurate in my description. – zmo Aug 13 '15 at 23:42
2

Shell scripts is a general name for any script that can be run by a system shell.

Now shell a program that takes commands and executes them - kind of a REPL / command interpreter. sh is a shell. So is bash, fish, zsh, etc.

cmd is sometimes called a Windows shell, but windows shell is the official name of the Windows UI. Microsoft calls it command interpreter (more name confusion).

Scripts for cmd and msdos are typically called "batch scripts".

So in *nix land it's usually: "bash" executing "shell scripts". And in the windows land: "cmd" (dos prompt) executing "batch scripts".

viraptor
  • 33,322
  • 10
  • 107
  • 191
0

According to wikipedia :

A shell script is a computer program designed to be run by the Unix shell, a command line interpreter.[1] The various dialects of shell scripts are considered to be scripting languages.

source : https://en.wikipedia.org/wiki/Shell_script

Bash is a command processor that typically runs in a text window, where the user types commands that cause actions. Bash can also read commands from a file, called a script.

In other word, bash is just a shell (a popular one) and a shell script is a script that can be interpreted by a shell. Here is a list of shell for your curiosity: https://en.wikipedia.org/wiki/Unix_shell#Shell_categories

chesbo
  • 21
  • 4
  • *a shell script is the script that you wrote in a language that bash can interpret* → no, it is what you wrote in a language a _SHELL_ can interpret, _Bash_ being just one shell amongst others. – zmo Aug 13 '15 at 23:40
  • Thank you for the comment! I will edit it to make it more appropriate. – chesbo Aug 13 '15 at 23:43