File tree Expand file tree Collapse file tree 9 files changed +107
-0
lines changed Expand file tree Collapse file tree 9 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -58,4 +58,5 @@ Each of these examples demonstrates one aspect or feature of bashly.
5858## Other Examples
5959
6060- [ heredoc] ( heredoc#readme ) - using heredoc strings
61+ - [ heredoc-alt] ( heredoc-alt#readme ) - using heredoc strings in the lib directory
6162- [ settings] ( settings#readme ) - using the settings.yml file to adjust bashly's behavior
Original file line number Diff line number Diff line change 1+ cli
Original file line number Diff line number Diff line change 1+ # Heredoc Alternative Example
2+
3+ This example shows how you can use * Here document* (heredoc) constructs without
4+ forcing the entire script to use tab indentation.
5+
6+ Code in the ` src/lib ` directory is injected to your script as is, so in cases
7+ where you must use heredocs, this is where you can.
8+
9+ This example was generated with:
10+
11+ ``` bash
12+ $ bashly init
13+ $ bashly add lib
14+ # ... now edit src/bashly.yml to match the example ...
15+ # ... now edit src/root_command.sh to match the example ...
16+ # ... now edit src/lib/heredocs.sh to match the example ...
17+ $ bashly generate
18+ ```
19+
20+ <!-- include: src/root_command.sh src/lib/heredocs.sh -->
21+
22+ -----
23+
24+ ## ` bashly.yml `
25+
26+ ``` yaml
27+ name : cli
28+ help : Sample application showing the use of heredoc
29+ version : 0.1.0
30+ ` ` `
31+
32+ ## ` src/root_command.sh`
33+
34+ ` ` ` bash
35+ text="$(message1)"
36+ echo "$text"
37+ ` ` `
38+
39+ # # `src/lib/heredocs.sh`
40+
41+ ` ` ` bash
42+ message1() {
43+ cat << EOF
44+ this is a
45+ multiline
46+ heredoc text
47+ EOF
48+ }
49+
50+ ` ` `
51+
52+
53+ # # Generated script output
54+
55+ # ## `$ ./cli`
56+
57+ ` ` ` shell
58+ multiline
59+ heredoc text
60+ this is
61+ an indented
62+ multiline text
63+
64+
65+ ` ` `
66+
67+
68+
Original file line number Diff line number Diff line change 1+ name : cli
2+ help : Sample application showing the use of heredoc
3+ version : 0.1.0
Original file line number Diff line number Diff line change 1+ # # Code here runs inside the initialize() function
2+ # # Use it for anything that you need to run before any other function, like
3+ # # setting environment vairables:
4+ # # CONFIG_FILE=settings.ini
5+ # #
6+ # # Feel free to empty (but not delete) this file.
Original file line number Diff line number Diff line change 1+ message1 () {
2+ cat << EOF
3+ this is a
4+ multiline
5+ heredoc text
6+ EOF
7+ }
Original file line number Diff line number Diff line change 1+ text=" $( message1) "
2+ echo " $text "
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -x
4+
5+ bashly generate
6+
7+ # ## Try Me ###
8+
9+ ./cli
Original file line number Diff line number Diff line change 1+ + bashly generate
2+ creating user files in src
3+ skipped src/initialize.sh (exists)
4+ skipped src/root_command.sh (exists)
5+ created ./cli
6+ run ./cli --help to test your bash script
7+ + ./cli
8+ this is a
9+ multiline
10+ heredoc text
You can’t perform that action at this time.
0 commit comments