I have recently started bash scripting, with little prior coding experience, and want to see how the below code could be cleaner/improved.
This is a subsection of a bigger script, but the point of it is to redact '42' from a file (secretinfo.md) and replace it with XX and then put the file in the new location. I don't want to delete the original file.
$files is defined earlier as the variable for a for-loop going through my target directory.
if [ "$files" == "source/secretinfo.md" ]
then
echo $files "is being redacted."
cd source/
cp secretinfo.md secretinfo_redacted.md
sed -i 's/42/XX/g' secretinfo_redacted.md
mv secretinfo_redacted.md ../build/
echo $files "has been copied."
cd ..
else
echo $files "is being copied into build for you."
cp $files build/.
fi
done
Thanks for any tips or tricks.
$files
defined? Is it supposed to be one file or many? Is it a string or an array? What is thefor
loop? – terdon Oct 19 '23 at 12:27