Skip to content

Commit 9ff599e

Browse files
chore(bash): be more bash resilient
Based on Jan advices :)
1 parent 1faaae8 commit 9ff599e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

check.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#!/bin/bash -e
1+
#!/usr/bin/env bash
22

3-
if [[ $ZSH_NAME != "" ]]; then
3+
set -eu
4+
5+
if [[ -v ZSH_NAME ]]; then
46
setopt BASH_REMATCH
57
setopt RE_MATCH_PCRE
68
setopt KSH_ARRAYS

validator.sh

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#!/bin/bash -e
2-
3-
if [[ $ZSH_NAME != "" ]]; then
1+
if [[ -v ZSH_NAME ]]; then
42
setopt BASH_REMATCH
53
setopt RE_MATCH_PCRE
64
setopt KSH_ARRAYS
@@ -140,9 +138,11 @@ validate_header() {
140138

141139
validate_header_length() {
142140
local HEADER="$1"
143-
local LENGTH=`echo -n "$HEADER" | wc -c`
141+
local LENGTH
142+
143+
LENGTH="$(echo -n "$HEADER" | wc -c)"
144144

145-
if [ $LENGTH -gt 70 ]; then
145+
if [[ $LENGTH -gt 70 ]]; then
146146
echo -e "commit header length is more than 70 charaters"
147147
exit $ERROR_HEADER_LENGTH
148148
fi
@@ -181,9 +181,11 @@ validate_body_length() {
181181

182182
while IFS= read -r LINE ;
183183
do
184-
local LENGTH=`echo -n "$LINE" | wc -c`
184+
local LENGTH
185+
186+
LENGTH="$(echo -n "$LINE" | wc -c)"
185187

186-
if [ $LENGTH -gt 100 ]; then
188+
if [[ $LENGTH -gt 100 ]]; then
187189
echo -e "body message line length is more than 100 charaters"
188190
exit $ERROR_BODY_LENGTH
189191
fi
@@ -222,7 +224,7 @@ validate_jira() {
222224
local TYPE=$1
223225
local JIRA=$2
224226

225-
if [[ `need_jira "$TYPE"` -eq 1 && $JIRA = "" ]]; then
227+
if [[ "$(need_jira "$TYPE")" -eq "1" && -z "${JIRA:-}" ]]; then
226228
echo -e "${TYPE} need a jira reference"
227229
exit $ERROR_JIRA
228230
fi

0 commit comments

Comments
 (0)