The syntax of bash more complicated than a one-liner still trips me up.
Yesterday at work I wanted to write a short script to read each line in a file, and use Rubocop to auto-correct the issue type listed on that line. I googled how to iterate over each line of a file and got the following example code:
while read p; do
echo $p
done <peptides.txt
Which I quickly modified into something like the following:
while read cop; do
git checkout -b $cop
rubocop --autocorrect --only $cop
git add .
git commit -m "fix issue with $cop
fixes INTERNAL-TRACKING-NUMBER
auto-corrected errors found by $cop."
git push origin HEAD:ref/for/master
git checkout master
done <cops.txt
However, when I ran the script on a small sample the commits came out borked. I started working on this around four on a Friday afternoon, and after googling and trying a few different things, it was well past five and I needed to start making dinner.
But it's been bugging me since, and so I'm curious, what's an elegant (for bash) way to get the multiline commit to work within a script like this?
It looks like there's a few options here: https://coderwall.com/p/-rlneg/multi-line-git-commit-message-from-cli