mercredi 27 février 2019

Variable comparison and pattern replacement

I am trying to create a bash script that uses the sed command to replace a pattern by a variable that contains a string or put a space if there is nothing in the variable. I cannot find the good way to write it and make it work. Here is the part where I have issues:

a_flag=$(echo $a | wc -w)

if  [[ $a_flag = 0 ]]; then
    sed -i -e 's/#b/\\hspace{2cm}/g' source.tex
else
    sed -i -e "s/#b/$a/g" source.tex
fi

When running this, the condition is always false. I tried [] or (()) for the if statement but I just can't find a way to fix it.

Aucun commentaire:

Enregistrer un commentaire