Bash – The files with the extension bash and sh

bashshellshell-script

I made some researches about the files with bash and sh extensions. Most of the people and resources say that if a file has bash extension, then it contains bash scripts. Likewise, the file with sh extensions contains sh scripts.

However, I cannot find the differences between bash and sh scripting. There are some courses and articles which aim to teach the people to write scripts on shell, and all of them has the title shell scripting.

In this point, which one does shell scripting correspond to ?

Bash Scripting or Sh scripting.

What I try to understand is what is the difference between bash and sh scripting.

Best Answer

File names in POSIXland don't have "extensions". A . in a filename is no different from any other character and has no specific meaning other than those that might be attributed to them by meatbags such as ourselves.

One could hope that any file with a name ending in .bash would be a script meant to be executed via the bash shell, but there is no guarantee of this.

Indeed, it's quite common to give all shell scripts a suffix of .sh no matter which interpreter is intended for their use, as the shebang line should properly specify which shell should be used to execute such a file.

sh and bash are two different, but related, shells; two amongst many others such as ksh, csh, zsh, fish, ash, dash, and yet more others.

Each shell has its own syntax, capabilities, mannerisms, and foibles; some shells are largely compatible with each other (generally any script written for sh can also be run in bash or many other shells), but some are not.

Related Question