通过管道传输到 awk 的 svn 命令的 Bash 别名
我经常输入这个命令,并试图给它起别名,但由于某种原因不能。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我注意到您对解决方法不感兴趣,但它似乎与本机方式一样有用。不要使用别名,而是定义为函数并放入 .bashrc:
刚刚测试:
有效。
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:
Just tested:
works.
你不能直接执行
svn revert --recursive
吗?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.
反引号使得正确引用变得非常困难。
试试这个:
使用
$()
允许其内部的引号独立于其外部的引号。最好始终使用
$()
并且永远不要使用反引号。Backticks make getting the quoting right very difficult.
Try this:
Using
$()
allows quotes inside it to be independent of quotes outside it.It's best to always use
$()
and never use backticks.最简单的方法是完全避免反引号:
接下来是使用 eval。
The simplest way is to avoid the backticks completely with:
The next is to use eval.