Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash alias of an svn command piped to awk

Tags:

bash

svn

awk

I type in this command frequently, and was trying to alias it, and couldn't for some reason.

for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done

This obviously does a large number of svn reverts.

when I alias it:

alias revert_all="for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done"

svn stat runs immediately - no good

Then I try double-quoting the awk portion:

alias revert_all='for FILE in `svn stat | awk "{print $2}"`; do svn revert $FILE; done'

but this does not run properly - the awk portion does not execute (I get the M values showing up and try to run svn revert M).

next try, with escaped single tick quotes:

alias revert_all='for FILE in `svn stat | awk \'{print $2}\'`; do svn revert $FILE; done'

The command does not complete, bash is waiting for another tick?

I know I could script this, or put the awk command in the file, but I'm not looking for a workaround. There is something here I don't know. What is it?

TIA

like image 991
theschmitzer Avatar asked Dec 18 '25 23:12

theschmitzer


2 Answers

I note you are not interesting in workarounds, but it seems as much usefull the native way. Do not alias, but define as function and put .bashrc:

revert_all() { for FILE in `svn stat | awk '{print $2}'`; do svn revert $FILE; done}

Just tested:

alias revert_all="for FILE in \`svn stat | awk '{print $2}'\`; do svn revert $FILE; done"

works.

like image 174
Artem Barger Avatar answered Dec 20 '25 15:12

Artem Barger


Can’t you just do svn revert --recursive?

like image 40
Michael Hackner Avatar answered Dec 20 '25 16:12

Michael Hackner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!