简体   繁体   English

为什么某些命令在使用 bash 别名运行时表现不同?

[英]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.

相关问题 为什么printf和sprintf在给定数组时表现不同? - Why do printf and sprintf behave differently when only given an array? 为什么这两个正则表达式的行为不同? - Why do these two regexes behave differently? 为什么这些代码块的行为不同? - Why do these blocks of code behave differently? 为什么这两种确定打印列数的方法表现不同? - Why do these two methods to determine the number of print columns behave differently? 为什么Perl的“系统('某些命令')”与c:\\>某些命令的行为有所不同? - Why does Perl's “system ('some command')” behave differently from c:\> some command? bash shellshock更新导致脚本行为不同 - bash shellshock update causing script to behave differently 如果我从图标运行它与从命令行运行它,为什么我的perl脚本的行为会有所不同? - Why does my perl script behave differently if I run it from the icon vs running it from the command line? 为什么要使用“ perl Foo.pm”和“ perl -I”。 -mFoo -e1`表现不同吗? - Why do `perl Foo.pm` and `perl -I. -mFoo -e1` behave differently? 为什么在调试器下Perl的quotemeta()函数表现不同? - Why does Perl's quotemeta() function behave differently when under the debugger? 从我的Web应用程序调用时,为什么PDF :: FromHTML的行为会有所不同? - Why would PDF::FromHTML behave differently when called from my web app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM