一个SVN命令别名猛砸管道输送到awk的 [英] Bash alias of an svn command piped to awk

查看:182
本文介绍了一个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

这显然是大量的svn将会恢复。

This obviously does a large number of svn reverts.

当我它的别名:

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

SVN统计立即运行 - 没有好

svn stat runs immediately - no good

然后我尝试双引号awk的部分:

Then I try double-quoting the awk portion:

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

但是,这并不正常运行 - awk的部分不执行(我得到的M值显示出来,并尝试运行svn恢复M)

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?

我知道我可以脚本中,或者在文件中把awk命令,但我不是在寻找一个解决办法。这里有一些我不知道的。这是什么?

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

推荐答案

反引号使得到正确的报价非常困难的。

Backticks make getting the quoting right very difficult.

试试这个:

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.

这篇关于一个SVN命令别名猛砸管道输送到awk的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆