Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created April 25, 2015 22:53
Show Gist options
  • Save johana-star/0e38ab5f3d0c41143e8c to your computer and use it in GitHub Desktop.
Save johana-star/0e38ab5f3d0c41143e8c to your computer and use it in GitHub Desktop.

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?

@johana-star
Copy link
Author

Ooh, looks like a $ or multiple -ms might be in my future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment