$ VAR="this is working well" $ sed -i "s/$/,$VAR/" my.txt $ VAR="this/got/error" $ sed -i "s/$/,$VAR/" my.txt sed: -e expres