Skip to content

Commit 63a826d

Browse files
committed
new bash description and resources
1 parent 9430638 commit 63a826d

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

content/pages/02-development-environments/08-bash-shell.markdown

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,62 @@ with this shell:
108108
common operators and signals that come up when working with scripts.
109109

110110

111+
### Bash scripting
112+
Bash is used not only as an interactive prompt but also for scripting, which
113+
makes it possible to execute one or more Bash commands stored within a file.
114+
These scripts can be short, with only a single command, or very complicated
115+
with control-flow logic, for loops, and almost anything you want to automate
116+
or compute because
117+
[Bash is a Turing-complete programming language](https://www.quora.com/Is-Bash-Turing-complete).
118+
119+
Complex Bash scripts sometimes get a negative reputation because they can be
120+
difficult to read and understand if you are not the original author (or you
121+
are reading your own script after a significant period of time has elapsed).
122+
There are many ways to accomplish the same tasks with Bash so the files are
123+
often confusing to read unless the author of a script included clear
124+
documentation. This readability problem is typically less of an issue with
125+
Python scripts because spacing is enforced and the standard library
126+
encapsulates common tasks.
127+
128+
It's a good idea to think about how you want to structure your Bash scripts
129+
as they grow larger. The following resources provide insight into what you
130+
should consider while coding Bash scripts.
131+
132+
* This [minimal safe Bash template](https://betterdev.blog/minimal-safe-bash-script-template/)
133+
contains an 86-line Bash script that the author claims once you
134+
understand and use it as a base then it will make your scripts
135+
easier to maintain over time.
136+
137+
* [Creating a bash completion script](https://iridakos.com/tutorials/2018/03/01/bash-programmable-completion-tutorial.html)
138+
is a great tutorial that walks you through a reasonably complex Bash
139+
script for completing syntax in other Bash shell scripts.
140+
141+
* [Anybody can write good bash (with a little effort)](https://blog.yossarian.net/2020/01/23/Anybody-can-write-good-bash-with-a-little-effort)
142+
covers the basics of shell scripting and provides some recommendations
143+
for creating more maintainable scripts such as using linters and
144+
formatters.
145+
146+
* Google's [Shell Style Guide](https://google.github.io/styleguide/shell.xml)
147+
covers how to write consistent, maintainable shell scripts, which is
148+
particularly important if you have ever tried to debug a hacky shell
149+
script that was never meant to be used by anyone other than the original
150+
author.
151+
152+
* [Bash scripting quirks & safety tips](https://jvns.ca/blog/2017/03/26/bash-quirks/)
153+
explains Bash basic programming constructs like `for` loops and variable
154+
assignment then goes into ways to avoid weird issues in your code.
155+
156+
* If all else fails when you're trying to use Bash scripts, this article
157+
on [replacing Bash scripts with Python](https://github.com/ninjaaron/replacing-bash-scripting-with-python)
158+
is a guide on swapping in Python for administrative scripting, including
159+
what to do about replacing invaluable command line tools such as `awk`,
160+
`sed` and `grep`.
161+
162+
111163
### Additional Bash resources
164+
The following resources cover more advanced Bash use cases and what pitfalls
165+
to try to avoid as you work with the shell or write scripts.
166+
112167
* [Advancing in the Bash shell](http://samrowe.com/wordpress/advancing-in-the-bash-shell/)
113168
covers important concepts such as bang syntax, movement commands,
114169
tab completion and aliases.
@@ -129,16 +184,6 @@ with this shell:
129184
`PROMPT_COMMAND`, `CDPATH` and `REPLY` which can simplify your
130185
scripts by using values that Bash already has stored for you.
131186

132-
* Google's [Shell Style Guide](https://google.github.io/styleguide/shell.xml)
133-
covers how to write consistent, maintainable shell scripts, which is
134-
particularly important if you have ever tried to debug a hacky shell
135-
script that was never meant to be used by anyone other than the original
136-
author.
137-
138-
* [Bash scripting quirks & safety tips](https://jvns.ca/blog/2017/03/26/bash-quirks/)
139-
explains Bash basic programming constructs like `for` loops and variable
140-
assignment then goes into ways to avoid weird issues in your code.
141-
142187
* [Safe ways to do things in bash](https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md)
143188
shows you how to not shoot yourself in the foot by using safe coding
144189
practices with your shell scripts.
@@ -156,19 +201,10 @@ with this shell:
156201
application that generates a hostable, customizable status page for your
157202
services.
158203

159-
* [Replacing Bash scripts with Python](https://github.com/ninjaaron/replacing-bash-scripting-with-python)
160-
is a guide on using using Python for administrative scripting, including
161-
what to do about replacing invaluable command line tools such as `awk`,
162-
`sed` and `grep`.
163-
164204
* [Using Aliases to Speed Up Your Git Workflow](https://dev.to/robertcoopercode/using-aliases-to-speed-up-your-git-workflow-2f5a)
165205
has a bunch of shell aliases that make it easier for you to execute
166206
complicated or uncommon [Git](/git.html) commands.
167207

168-
* [Creating a bash completion script](https://iridakos.com/tutorials/2018/03/01/bash-programmable-completion-tutorial.html)
169-
is a great tutorial that walks you through a reasonably complex Bash
170-
script for completing syntax in other Bash shell scripts.
171-
172208
* [6 Tips Before You Write Your Next Bash Cronjob](https://yasoob.me/posts/6-tips-before-you-write-your-next-bash-cronjob/)
173209
covers starting your scripts with shebang, redirecting output, timeouts
174210
and sudo privileges.
@@ -190,7 +226,3 @@ with this shell:
190226
open new Bash shells. On many systems you can easily cut down the startup
191227
time for the shell which can be unnecessarily sluggish.
192228

193-
* [Anybody can write good bash (with a little effort)](https://blog.yossarian.net/2020/01/23/Anybody-can-write-good-bash-with-a-little-effort)
194-
covers the basics of shell scripting and provides some recommendations
195-
for creating more maintainable scripts such as using linters and
196-
formatters.

0 commit comments

Comments
 (0)