Bourne Shell: Difference between revisions

Content added Content deleted
(repair link, citation)
(repair syntax highlighting)
 
Line 7: Line 7:
A Bourne Shell script begins with a [[wp:shebang (Unix)|shebang]] (also known as a ''hashbang'') like this, which tells the operating system to use the Bourne compatible shell interpreter:
A Bourne Shell script begins with a [[wp:shebang (Unix)|shebang]] (also known as a ''hashbang'') like this, which tells the operating system to use the Bourne compatible shell interpreter:


<syntaxhighlight lang="sh">
#!/bin/sh
#!/bin/sh
</syntaxhighlight>


In 2009, ''[[wp:Computerworld|Computerworld]]'' published an in-depth interview with Steve Bourne, "[https://web.archive.org/web/20100212210742/computerworld.com.au/article/279011/a-z_programming_languages_bourne_shell_sh/ The A-Z of Programming Languages: Bourne shell, or sh]", which details the Bourne shell origins and design decisions.
In 2009, ''[[wp:Computerworld|Computerworld]]'' published an in-depth interview with Steve Bourne, "[https://web.archive.org/web/20100212210742/computerworld.com.au/article/279011/a-z_programming_languages_bourne_shell_sh/ The A-Z of Programming Languages: Bourne shell, or sh]", which details the Bourne shell origins and design decisions.
Line 14: Line 16:
Bourne Shell and Heirloom Shell have problems with here documents. Here is one such problem. A substitution, inside a here document, inside backquotes, inside double quotes, does insert too many backslashes.
Bourne Shell and Heirloom Shell have problems with here documents. Here is one such problem. A substitution, inside a here document, inside backquotes, inside double quotes, does insert too many backslashes.


<lang bash>f() {
<syntaxhighlight lang="sh">f() {
cat <<!
cat <<!
here $1
here $1
Line 22: Line 24:
expr "`f string`"
expr "`f string`"
# Output from Bourne Shell: here \s\t\r\i\n\g
# Output from Bourne Shell: here \s\t\r\i\n\g
# Correct output: here string</lang>
# Correct output: here string</syntaxhighlight>


The workaround is to move the backquotes to an assignment.
The workaround is to move the backquotes to an assignment.


<lang bash>f() {
<syntaxhighlight lang="sh">f() {
cat <<!
cat <<!
here $1
here $1
Line 34: Line 36:
var=`f string`
var=`f string`
expr "$var"
expr "$var"
# Output: here string</lang>
# Output: here string</syntaxhighlight>