Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
for name in $(cat repos.txt); do
echo $name;
repo=$(echo $name | cut -d'/' -f2);
echo $repo;
hub clone $name;
cd $repo;
hub fork;
pwd && grep -lZR 'panic!' . | xargs -0 -l sed -i -e 's/panic!/panic!/g';
git add -A;
git commit -m 'fail -> panic';
hub pull-request -m <<-EOM fail -> panic
Sorry I broke your code with rust-lang/rust#17894 ! Here's a fix :heart:
(this is a semi-automatic PR, so sorry if it's not perfect. Let me know and I'll fix any problems.)'
EOM
cd ..;
done
@johnbender
Copy link

sed -i'' for in place?

That might be for OS X? I don't remember the difference with the GNU version. Mind you the -i'' means no backups, before you try it.

@steveklabnik
Copy link
Author

The sed works when i type it in a regular shell.

@foca
Copy link

foca commented Oct 30, 2014

Yep. -i -e will suffix the modified files with -e, which means that it doesn't recognise -e as a switch (just the value of -i. That should fix it.

@foca
Copy link

foca commented Oct 30, 2014

Ah, then that's a GNU vs BSD thing.

@mgpcoe
Copy link

mgpcoe commented Oct 30, 2014

I find in bash I always have issues using ! without escaping it on the terminal line. Is it possible your xargs is getting tripped up on the ! ?

@purp
Copy link

purp commented Oct 30, 2014

@steveklabnik - when you say the sed works fine, are you talking about the sed part only or the whole of line 10? I'm wondering if it's xargs failing and/or quoting issues inside a bash script vs. command line (as @mgpcoe notes above)

@rhunter
Copy link

rhunter commented Oct 30, 2014

I ran the script with set -e (to stop on error) and set -x (to show output as executed).

The relevant bit of output (OS X):

+ grep -lZR 'panic!' .
+ xargs -0 -l sed -i -e 's/panic!/panic!/g'
xargs: illegal option -- l
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]

My xargs (OS X) doesn't have a -l (and the GNU man page says -l is deprecated anyway). I switched it out for -L 1 and that line completes (and instead has problems with "nothing to commit" after replacing panic with panic.

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