| #!/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 |
The sed works when i type it in a regular shell.
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.
Ah, then that's a GNU vs BSD thing.
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 ! ?
@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)
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.
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.