Skip to content

Commit 3ba95cc

Browse files
committed
🖨 Adds paradigm documentation
1 parent 43b14bb commit 3ba95cc

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

‎paradigm.sh

100644100755
+26-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

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+
310
help() {
411
# This will get called if there is an error
512
echo $0 [function] [args]
@@ -16,17 +23,31 @@ bar() {
1623
# Call a function in this script and store the output in a variable
1724
BAR=$(foo bar)
1825
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.
1930
}
2031

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+
'
2538

2639
"$@" || (help && exit 1)
2740

2841
: '
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:
3051
./script foo bar
3152
-> bar
3253

0 commit comments

Comments
 (0)