[英]Why do some commands behave differently when run using a bash alias?
In developing with SVN, sometimes I want to just rollback all my changes and start fresh, so I put together a command to revert all the files in my checkout:在使用 SVN 进行开发时,有时我只想回滚所有更改并重新开始,所以我整理了一个命令来恢复结帐中的所有文件:
alias "svn-reset"="svn status | perl -nale 'print $F[1] if /^M/' | xargs svn revert"
When I run svn status | perl -nale 'print $F[1] if /^M/' | xargs svn revert
当我运行
svn status | perl -nale 'print $F[1] if /^M/' | xargs svn revert
svn status | perl -nale 'print $F[1] if /^M/' | xargs svn revert
svn status | perl -nale 'print $F[1] if /^M/' | xargs svn revert
on the command line, the code works as expected: all my modified files get reverted, as verified with another svn status
command. svn status | perl -nale 'print $F[1] if /^M/' | xargs svn revert
在命令行上恢复,代码按预期工作:我修改的所有文件都得到恢复,正如另一个svn status
命令所验证的那样。 However, when I run svn-reset
, I get output like the following:但是,当我运行
svn-reset
时,我得到 output 如下所示:
$ svn-reset
Skipped 'ARRAY(0x1c2f52a0)'
Skipped 'ARRAY(0x1c2f5450)'
Skipped 'ARRAY(0x1c2f5410)'
In this example, I've verified that I have three modified files in my checkout, so it looks like the problem is with perl printing out the wrong information.在此示例中,我已验证我的结帐中有三个已修改的文件,因此看起来问题出在 perl 打印出错误信息。 However, I know hardly any perl, and I'm stumped as to why perl would behave differently run through a bash alias as compared to running the same perl code manually.
However, I know hardly any perl, and I'm stumped as to why perl would behave differently run through a bash alias as compared to running the same perl code manually. Any thoughts?
有什么想法吗?
This question is about why perl behaves differently when run using a bash alias.这个问题是关于为什么 perl 在使用 bash 别名运行时表现不同。 If anyone has any suggestions for a more efficient way to automatically revert all modified files in SVN, I'd be interested in that too, but that doesn't answer my question.
如果有人对自动还原 SVN 中所有修改文件的更有效方法有任何建议,我也会对此感兴趣,但这并不能回答我的问题。
Try escaping the dollar, so that the shell does not substitute $F
with nothing when you create the alias:尝试 escaping 美元,以便在创建别名时 shell 不会用任何内容替换
$F
:
alias svn-reset="svn status | perl -nale 'print \$F[1] if /^M/' | xargs svn revert"
This is how your alias looks like to the shell这就是您的别名在 shell 中的样子
output from alias
command: output 来自
alias
命令:
alias svn-reset='svn status | perl -nale '\''print [1] if /^M/'\'' | xargs svn revert'
after escaping the $
, it looks like this instead:在 escaping
$
之后,它看起来像这样:
alias svn-reset='svn status | perl -nale '\''print $F[1] if /^M/'\'' | xargs svn revert'
You used double quotes around the alias, so the shell is expanding the $F.您在别名周围使用了双引号,因此 shell 正在扩展 $F。 Change it to (untested):
将其更改为(未经测试):
alias "svn_reset"="svn status | perl -nale 'print \$F[1] if /^M/' | xargs svn revert"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.