In the below shell script, I'm trying to conditionally add elements to an array which is syntactically incorrect when checked in shellcheck.
#!/bin/bash
echo "Hello World";
HH=1
ARR=(
"a"
"b"
"c"
if [ ${HH} = 1 ]; then
"f"
else
"g"
fi
"d"
"e"
)
for arr in "${ARR[@]}"; do
echo "${arr}"
done
ShellCheck Error:
Line 6:
ARR=(
^-- SC1009 (info): The mentioned syntax error was in this variable assignment.
^-- SC1073 (error): Couldn't parse this array assignment. Fix to allow more checks.
Line 12:
if [ ${HH} = 1 ]; then
^-- SC1072 (error): Expected ) to close array assignment. Fix any mentioned problems and try again.