I have a condition, depending on which I want to either append or overwrite some file like this:
if [ "${CONDITION}" -eq 1 ]; then
echo "${INFO}" > "{$FILE}"
else
echo "{$INFO}" >> "{$FILE}"
fi
The thing is that 'if' and 'else' blocks are relatively big (20 lines each) and are essentially identical except the redirection difference. This makes me feel really bad indeed.
How can I avoid this bad style? I.e. I need to have only one block like this and define the append/overwrite action in some other way.
Aucun commentaire:
Enregistrer un commentaire