vendredi 11 septembre 2015

How would I sed replace a $VARIABLE in a $VARIABLE2 filename in a BASh (3.2) script for Mac

I have a BASh script which produces a script at /directory/filename.sh The file location and filename are a single variable. Because I used cat <<"EOT" >$FILELOCATION to produce the file, the file string is literal so I wasn't able to evaluate the variables inside it at the time it was produced. Instead, I used placeholders, then used sed afterwards.

Here is what I tried; in each instance, $NEWSTRING was not evaluated.

sed -i 's/STRINGTOREPLACE/$NEWSTRING/g' $FILELOCATION
sed -i 's/STRINGTOREPLACE/"$NEWSTRING"/g' $FILELOCATION
sed -i 's/STRINGTOREPLACE/'"$NEWSTRING"'/g' $FILELOCATION

Please advise on the correct way to evaluate a variable in sed within a BASh script.

Thank you!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire