I have a simple Bash shell Script to loop through each file in a directory and check is the copyright message is at the top of the file. If it's not there is should add it.
The script is giving an error when I try to use a variable in the sed command. I have looked at other similar questions and tried double quotes "", I have tried using a different operator but still can't find the solution. Can someone possibly point out what I am doing wrong?
Msg='/*------------------------------------------------------------------------------
*******************************************************************************
* Copyright message here
*******************************************************************************
*----------------------------------------------------------------------------*/'
for file in *
do
if grep -Fxq "$Msg" $file
then
echo Marvel Message already exist: $file
else
if test -f "$file"
then
echo "Adding Message to file: $file"
sed -i "1s/^/${Msg}\n/" $file
fi
fi
done