Skip to content

Commit f23b5fa

Browse files
committed
Move bash 3 version check to top of file for early exit
Bash executes the script as it's reading it. When it encounters a function, it parses the function body before continuing. The bashly-generated script has *all* of its code in functions which appear before any code is executed (the initialize/run functions are only called at the bottom of the script). Normally this is useful, since it ensures that bash has loaded/parsed the whole script before beginning execution; however, in the case of this version check it means that if any of the functions contain syntax that Bash 3 doesn't understand, it will choke on that and crash (with a much less helpful error) before it has a chance to execute the version check. This commit moves that check to the very top of the file, where it will be executed and trigger an early exit before bash tries to parse the rest of the script, so that it will work correctly regardless of the remainder of the contents.
1 parent bf3955a commit f23b5fa

File tree

30 files changed

+139
-139
lines changed

30 files changed

+139
-139
lines changed

examples/catch-all-advanced/cli

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -388,11 +393,6 @@ initialize() {
388393
long_usage=''
389394
set -e
390395

391-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
392-
printf "bash version 4 or higher is required\n"
393-
exit 1
394-
fi
395-
396396
# :src/initialize.sh
397397
# Code here runs inside the initialize() function
398398
# Use it for anything that you need to run before any other function, like

examples/catch-all/download

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.root_command
611
root_command() {
712
# :src/root_command.sh
@@ -161,11 +166,6 @@ initialize() {
161166
long_usage=''
162167
set -e
163168

164-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
165-
printf "bash version 4 or higher is required\n"
166-
exit 1
167-
fi
168-
169169
# :src/initialize.sh
170170
# Code here runs inside the initialize() function
171171
# Use it for anything that you need to run before any other function, like

examples/colors/colorly

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.root_command
611
root_command() {
712
# :src/root_command.sh
@@ -194,11 +199,6 @@ initialize() {
194199
long_usage=''
195200
set -e
196201

197-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
198-
printf "bash version 4 or higher is required\n"
199-
exit 1
200-
fi
201-
202202
# :src/initialize.sh
203203
# Code here runs inside the initialize() function
204204
# Use it for anything that you need to run before any other function, like

examples/command-default/ftp

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -373,11 +378,6 @@ initialize() {
373378
long_usage=''
374379
set -e
375380

376-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
377-
printf "bash version 4 or higher is required\n"
378-
exit 1
379-
fi
380-
381381
# :src/initialize.sh
382382
# Code here runs inside the initialize() function
383383
# Use it for anything that you need to run before any other function, like

examples/command-groups/ftp

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -536,11 +541,6 @@ initialize() {
536541
long_usage=''
537542
set -e
538543

539-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
540-
printf "bash version 4 or higher is required\n"
541-
exit 1
542-
fi
543-
544544
# :src/initialize.sh
545545
# Code here runs inside the initialize() function
546546
# Use it for anything that you need to run before any other function, like

examples/commands-nested/cli

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -778,11 +783,6 @@ initialize() {
778783
long_usage=''
779784
set -e
780785

781-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
782-
printf "bash version 4 or higher is required\n"
783-
exit 1
784-
fi
785-
786786
# :src/initialize.sh
787787
# Code here runs inside the initialize() function
788788
# Use it for anything that you need to run before any other function, like

examples/commands/cli

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -444,11 +449,6 @@ initialize() {
444449
long_usage=''
445450
set -e
446451

447-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
448-
printf "bash version 4 or higher is required\n"
449-
exit 1
450-
fi
451-
452452
# :src/initialize.sh
453453
# Code here runs inside the initialize() function
454454
# Use it for anything that you need to run before any other function, like

examples/completions/cli

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -553,11 +558,6 @@ initialize() {
553558
long_usage=''
554559
set -e
555560

556-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
557-
printf "bash version 4 or higher is required\n"
558-
exit 1
559-
fi
560-
561561
# :src/initialize.sh
562562
# Code here runs inside the initialize() function
563563
# Use it for anything that you need to run before any other function, like

examples/config-ini/configly

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.version_command
611
version_command() {
712
echo "$version"
@@ -624,11 +629,6 @@ initialize() {
624629
long_usage=''
625630
set -e
626631

627-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
628-
printf "bash version 4 or higher is required\n"
629-
exit 1
630-
fi
631-
632632
# :src/initialize.sh
633633
# Code here runs inside the initialize() function
634634
# Use it for anything that you need to run before any other function, like

examples/custom-includes/download

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
44

5+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
6+
printf "bash version 4 or higher is required\n"
7+
exit 1
8+
fi
9+
510
# :command.root_command
611
root_command() {
712
# :src/root_command.sh
@@ -171,11 +176,6 @@ initialize() {
171176
long_usage=''
172177
set -e
173178

174-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
175-
printf "bash version 4 or higher is required\n"
176-
exit 1
177-
fi
178-
179179
# :src/initialize.sh
180180
# Code here runs inside the initialize() function
181181
# Use it for anything that you need to run before any other function, like

0 commit comments

Comments
 (0)