Question

In my previous question I created a command that reverts svn files by pattern:

svn st | grep SomeFolderA | awk {'print $2'} | xargs svn revert

Now I want to make it a command that accepts argument (file pattern) and runs the above command by using the argument instead of SomeFolderA. I tried adding this to my .bash_profile file:

function revert() {
    "svn st | grep '$1' | awk '{print \$2}' | xargs svn revert" ;
}

When I run revert SomeFolderA I get this output:

-bash: svn st | grep 'SomeFolderA/' | awk '{print $2}' | xargs svn revert: No such file or directory

I also tried using the complete path for the svn but it still doesn't work. What am I missing?

Was it helpful?

Solution

Create a variable with your command string and execute it

function revert() {
  cmd="svn st | grep '$1' | awk '{print \$2}' | xargs svn revert"
  eval $cmd
}

OTHER TIPS

No need to use function, put off the function, just use below in you script :

svn st | grep "$1" | awk '{print \$2}' | xargs svn revert
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top