Syntax error when using array in bash script with husky

24 views Asked by At

In my pre-commit husky hook I'm display a select option to select the semantic version("Patch" "Minor" "Major"). When initialize the array I get this error .husky/post-commit: 20: Syntax error: "(" unexpected. This line is the initilization of the options array.

Code:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
. "$(dirname -- "$0")/config.cfg"

scriptsDir=$(echo "$(pwd)/scripts");
. "$scriptsDir/select.sh"

echo "\nSemantic version: ${darkGray}(use arrow keys)${noColor}"
echo

selectOptions=("Patch" "Minor" "Major")

select_option "${selectOptions[@]}"
choice=$?

echo "Choosen index = $choice"
echo "        value = ${selectOptions[$choice]}"

The select_option renders a text based list of options that can be selected by the user using up, down and enter keys and returns the chosen option. I don't think the issue is there as I tested it in test.sh script and it worked just fine.

Error:

.husky/pre-commit: 20: Syntax error: "(" unexpected
husky - pre-commit hook exited with code 2 (error)

Any ideas on what the problem might be?

0

There are 0 answers