通过管道传输到 awk 的 svn 命令的 Bash 别名

发布于 2024-08-13 01:37:12 字数 770 浏览 5 评论 0原文

我经常输入这个命令,并试图给它起别名,但由于某种原因不能。

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

这显然会进行大量的 svn 恢复。

当我给它加上别名时:

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

svn stat 立即运行 - 不好

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

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

但这不能正常运行 - awk 部分不执行(我得到显示的 M 值并尝试运行 svn revert M )。

下一次尝试,使用转义的单引号:

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

命令未完成,bash 正在等待另一个刻度?

我知道我可以编写这个脚本,或者将 awk 命令放入文件中,但我并不是在寻找解决方法。这里有一些我不知道的事情。它是什么?

TIA

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

笑咖 2024-08-20 01:37:12

我注意到您对解决方法不感兴趣,但它似乎与本机方式一样有用。不要使用别名,而是定义为函数并放入 .bashrc:

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

刚刚测试:

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

有效。

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.

烟燃烟灭 2024-08-20 01:37:12

你不能直接执行svn revert --recursive吗?

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

や三分注定 2024-08-20 01:37:12

为什么要使用别名?将其定义为函数并将其放入文件中。这将充当“图书馆”。当您想要使用该函数时,请在脚本中获取它。

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.

陪你到最终 2024-08-20 01:37:12

反引号使得正确引用变得非常困难。

试试这个:

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

使用 $() 允许其内部的引号独立于其外部的引号。

最好始终使用 $() 并且永远不要使用反引号

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.

半岛未凉 2024-08-20 01:37:12

最简单的方法是完全避免反引号:

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

接下来是使用 eval。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文