You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _docs/reference/bash-styles.adoc
+28-3Lines changed: 28 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,30 @@ See also {xref_docs_cli-styles_link} for guidance specific to command-line inter
17
17
[[file-and-script-structure]]
18
18
== File and Script Structure
19
19
20
+
With certain exceptions, shell scripting is done in Bash 4.
21
+
22
+
We will start with the exceptions.
23
+
24
+
[[posix-compliant]]
25
+
=== POSIX Compliant Scripts
26
+
27
+
Scripts that require maximum portability and compatibility should use the POSIX-compliant `sh` shell and avoid Bash-specific features.
28
+
29
+
These scripts must begin with the shebang `#!/bin/sh` and should be tested in a POSIX-compliant environment to ensure they do not rely on Bash extensions.
30
+
31
+
This standard is mainly to cover MacOS systems, which do not support Bash 4 out of the box.
32
+
Therefore, bootstrap/installer scripts will need to be executable in a Bash 3 environment, where they can prompt for Bash 4 installation if it is not detected and if it is needed by a follow-on script.
33
+
34
+
Such files should begin with:
35
+
36
+
[source,shell]
37
+
----
38
+
#!/bin/sh
39
+
# shellcheck shell=sh
40
+
----
41
+
42
+
The rest of this guide focuses on Bash 4 scripts, which are the norm for DocOps Lab projects and products that use basic shell scripts.
43
+
20
44
[[bash-version]]
21
45
=== Bash Version (4.0)
22
46
@@ -41,8 +65,8 @@ Keep it compact: one line per thought, no visual padding.
41
65
[source,bash]
42
66
----
43
67
#!/usr/bin/env bash
44
-
# script-name: brief description of what the script does.
45
-
# Depends on: curl, jq
68
+
# script-name.sh: brief description of what the script does.
69
+
# Requires: curl, jq
46
70
----
47
71
48
72
[[indentation]]
@@ -175,7 +199,7 @@ Use `snake_case` and `local` declaration.
175
199
176
200
Operation functions::
177
201
The substantive work of a script; what `cmd_` functions orchestrate, and what sourced libraries export as their callable API.
0 commit comments