Linux Shell :
What is "the Shell"?
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform
https://linuxcommand.org/lc3_lts0010.php
https://www.quora.com/What-is-the-difference-between-Shell-scripting-and-Bash-Shell-scripting
A2A. You ask: What is the difference between Shell scripting and Bash Shell scripting?
- Shell scripting refers to scripts meant to be interpreted by an unspecified command line interpreter typical of UNIX and UNIX-like systems.
Most of those command line interpreters (including GNU Bash) adopted a syntax deriving from the one used by the (David) Bourne Shell, which was the default command line interpreter used in Version 7 UNIX (1979).
More recently, the syntax and behaviour had been standardized by POSIX.2 (1992) — nonetheless still leaving some areas where behaviour is implementation-defined (see for example the differences between the Korn Shell and GNU Bash when starting sub-shells¹ — both behaviours are allowed by POSIX.2).
Notable exceptions to this are the C shell (csh) and its derivatives, which adopted a different syntax (more C-like), but are generally not considered suitable for shell scripting; - GNU Bash is a specific command line interpreter, among the most popular ones (it’s the default interactive interpreter on most operating systems based on Linux), but:
- its default behaviour slightly deviates from the one mandated by POSIX.2 — but it can be configured to adhere more strictly to that standard if needed. A complete list can be found in the Bash Reference Manual: Bash POSIX Mode;
- it supports also constructs and behaviours which are neither standardized by POSIX.2, nor are commonly found in other command line interpreters (for example, associative arrays)
In the end, the difference between Shell scripting and Bash Shell Scripting is that the latter is supposed to work properly only when the underlying command line interpreter is specifically GNU Bash, rather than a generic, POSIX.2-compilant command line interpreter.
¹ For example, consider the following line:
- s=0; echo "3+4"|bc|read s; echo $s
In GNU Bash (and some other shells) it will print 0
; in some other shells it will print 7
The reason is that GNU Bash always executes the “echo "3+4"|bc|read s
;” part in a subshell, so the “s
” variable being modified is the one in the subshell, while the one in the parent shell stays unmodified (and set to 0
).
Other shells (e.g. the Korn shell) do not start a subshell for a command like this, so the “s” variable being modified is the same as the one in the shell executing the final “echo $s
”.
Both behaviours are allowed by POSIX.
No comments:
Post a Comment