Shell Scripting Language (Unix Shell Scripting And Programming Language)
The shell programming language is almost a standard for the Linux and Unix platforms. The shell scripting is a programming language similar with the powershell. The shell programming has small variations as implementation that differ between sh, ksh, ash, bash, dash and others but mostly they have all implemented the minimal standard shell language scripting.
A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.
The most popular shells that are mostly accepted as a standard for (unix) shell scripting are: `bash` (Bourne-Again Shell) and `ksh` (KornShell). Most of the other shells are implementing the bash or ksh shell syntax.
Bash is a Unix shell and command language (mostly found on Linux) written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.
Ksh (the KornShell), developed by David Korn at Bell Labs is a more traditional shell (mostly found on BSD/Unix) that complies with POSIX.2, Shell and Utilities, Command Interpreter. KornShell is backward-compatible with the Bourne shell.
Current (stable) version - Bash: 5.2.x
A shell script is a computer program designed to be run by the Linux / Unix shell, a command-line interpreter. Other platforms like MS DOS and Windows have their own scripting language called batch scripting or powershell. MacOS has adopted the shell scripting language starting with the new line of Mac OSX platform, as previous they had only Applescript. The shell scripting and programming language has a high level of functionalities compared with the above mentioned scripting languages, except powershell which has been reinvented lately to offer a close enough as concept mostly for administration tasks.
The various dialects of shell scripts are considered to be scripting languages. 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, logging, etc. is called a wrapper.
The shell scripting language can be run by the OS in the command line interface. It can contain conditionals (IF), loop (FOR), regular expressions, file system access and many more.
The typical Unix/Linux/POSIX-compliant installation includes the KornShell (ksh) and the Bourne-Again Shell (bash) which is the most popular and considered a standard for shell scripting under Unix/Linux/POSIX-compliant environments.
The difference between ksh and bash are minimal. There are certain advantages one has over the other, but the differences are tiny:
- in bash is much easier to set a prompt that displays the current directory ; to do the same in ksh is hackish
- ksh has associative arrays and bash doesn't, but this is not a common required feature ...
- ksh handles loop syntax a bit better ; you can usually set a value in a ksh loop and have it available after the loop
- bash handles getting exit codes from pipes in a cleaner way
- ksh has the print command which is way better than the echo command.
Sample Code: Shell Scripting Syntax - bash / ksh
# shell script (bash / ksh): bash test.sh ; ksh test.sh
helloWorld() {
runTest=$1
myString1="Hello"
myString2="World"
myNumber=1
# in traditional shell scripting there is no other way to enforce bool types ...
if [ $runTest = true ] ; then
myTest=true
else
myTest=false
fi
myOutput="Test was disabled ..."
if [ $myTest = true ] ; then
myOutput="${myString1} ${myString2}, this is number: ${myNumber}"
fi
echo "${myOutput}" # this is an emulated return that echoes and will be captured later
}
testResult=$(helloWorld true) # capture the echo of the function and use it as a return
echo "${testResult}";
#end shell script (bash / ksh)
(c) w3soft.org, license: CC BY-SA 3.0FAQs - Frequently Asked Questions about POSIX / Linux / Unix Shell
- Question:
What is shell scripting language ?
The shell scripting language is a kind of scripting language that can be run in a Linux or Unix compliant shell, generally used for operating system tasks. The standard of this scripting language is covered by sh
but many other shells like bash (Bourne Again Shell) or ksh (KornShell) have been implemented an extended syntax.
Some examples of the context for using shell scripting are: a shell script that runs several successive os commands to archive some data on disk ; a shell script that may apply a recursive chown/chmod over a directory to fix privileges - separate for files and folders ; a shell script that can run several commands to process some log files.
- Question:
Is shell scripting a programming language ?
Yes, the shell scripting language is a scripting language thus it can be considered also a programming language.
A scripting language is a kind of programming language that can be executed by a language interpreter
without the need to be compiled as executable. In this case the language interpreter is the command line interpreter - shell: sh, bash, ksh and other POSIX compliant shells.
- Question:
Is bash a scripting language ?
No, bash is not a scripting language it is a command line interpreter.
The bash, ksh and other shells are not scripting languages. They are command line interpreters that can run operating system commands as well as shell scripts.
- Question:
What language is bash written in ?
Bash is written entirely in C
language.
Most of the operating system components are written in C
language because it is an efficient and still a low level language that have a low memory footprint and because and because is more easier to use than assembly language.