Commit 3ba95cc 1 parent 43b14bb commit 3ba95cc Copy full SHA for 3ba95cc
File tree 1 file changed +26
-5
lines changed
1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
3
+ : ' paradigm.sh
4
+
5
+ This script is an example template for writing quality, reusable bash scripts.
6
+
7
+ See the examples at the bottom of the script for usage.
8
+ '
9
+
3
10
help () {
4
11
# This will get called if there is an error
5
12
echo $0 [function] [args]
@@ -16,17 +23,31 @@ bar() {
16
23
# Call a function in this script and store the output in a variable
17
24
BAR=$( foo bar)
18
25
echo bar: $BAR
26
+
27
+ # Stored variables are available to any functions called by this function
28
+
29
+ # Temporary variables can be passed inline to called functions.
19
30
}
20
31
21
- # This is where the magic is:
22
- # Running `"$@"` will execute the command passed to this script as a bash command
23
- # If there is an error parsing the command, the `help` function will be called
24
- # and the script will exit with code 1
32
+ : '
33
+ This is where the magic is:
34
+ Running `"$@"` will execute the command passed to this script as a bash command
35
+ If there is an error parsing the command, the `help` function will be called
36
+ and the script will exit with code 1
37
+ '
25
38
26
39
" $@ " || (help && exit 1)
27
40
28
41
: '
29
- Example usage:
42
+ Other benefits:
43
+ - Functions can be called directly from the CLI
44
+ - Script does not have to be installed beforehand
45
+ - Leaves no trace in your source
46
+
47
+ Warning:
48
+ This script will execute any command passed to it as a bash command. Hic sunt dracones.
49
+
50
+ Examples:
30
51
./script foo bar
31
52
-> bar
32
53
You can’t perform that action at this time.
0 commit comments