Bash alias of an svn command piped to 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.

  • Convert .gitignore to rsync merge filter include file? (with sed or awk)
  • Ignore empty results for xargs in Mac OS X
  • How to see changed lines with certain words and the containing file for a git commit? - Can git diff print a file name line prefix?
  • What's the simplest way to customize `git log`, truncating the author email at the `@`?
  • git log - how to get an xml output
  • Looking for a way automate the “bump version” with git flow
  • 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

  • Git Bash on Windows - Where to Store and How to Invoke Bash Scripts
  • Using a git alias from cmder
  • subversion merge - “has different repository root than”
  • How many files have changed?
  • sh.exe": syntax error near unexpected token `('
  • Modify files under svn in hook script
  • 5 Solutions collect form web for “Bash alias of an svn command piped to awk”

    Backticks make getting the quoting right very difficult.

    Try this:

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

    Using $() allows quotes inside it to be independent of quotes outside it.

    It’s best to always use $() and never use backticks.

    I not you are not interesting in workarounds, but seem as much 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.

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

    why do you want to use alias? define it as a function and put it inside a file. This will act as a “library”. When you want to use the function, source it in your scripts.

    The simplest way is to avoid the backticks completely with:

    svn stat | awk '{print $2}' | while read FILE; do svn revert $FILE; done
    

    The next is to use eval.

    Git Baby is a git and github fan, let's start git clone.