vendredi 21 mai 2021

Special character string compare to array elements BASH

Im trying to code a small markdown to DocuWiki converter myself as BASH practice, somehow I'm getting Syntax errors while executing following Code:

#!/bin/bash
Heading1=($(grep -E '^\={5}\s.*\s\={5}$' ZimSyntax.txt))
VAR='====='
for i in ${Heading1[@]}; do
    if [ "${Heading1[i]}"!="${VAR}" ]
        then
            echo $i     
    fi
done

Error: ./converter.sh: line 21: =====: syntax error: operand expected (error token is "=====")

Sample Array Data:

===== 
Heading
1
=====
=====
Heading
1
=====

Aucun commentaire:

Enregistrer un commentaire