如何获得~/.bashrc
别名$()
在运行时评估替换,而不是在执行 ~/.bashrc 时(打开终端时)?
我经常运行这个命令,所以我想为它添加一个别名:
svn diff -r $(svn info | grep ^Revision | awk {'print $2'}):HEAD $(svn info | grep ^URL | awk {'print $2'}) | colordiff
但是,当我将其添加~/.bashrc
为别名时,我发现评估被硬编码为我打开终端时的值:
$ alias
alias svnbranch='svn diff -r 178184:HEAD svn+ssh://branches/t4252 | colordiff'
如果我打开终端,~
则会出现错误:
svn: E155007: '/home/dotancohen' is not a working copy
svn: E155007: '/home/dotancohen' is not a working copy
svn: E155007: '/home/dotancohen' is not a working copy
svn: E155007: '/home/dotancohen' is not a working copy
$ alias
alias svnbranch='svn diff -r :HEAD | colordiff'
$
我已经尝试过这两种别名的变体~/.bashrc
,它们都具有相同的效果(正如我预期的那样):
alias svnbranch="svn diff -r $(svn info | grep ^Revision | awk {'print $2'}):HEAD $(svn info | grep ^URL | awk {'print $2'}) | colordiff"
alias svnbranch="svn diff -r `svn info | grep ^Revision | awk {'print $2'}`:HEAD `svn info | grep ^URL | awk {'print $2'}` | colordiff"
如何获取别名来在运行时~/.bashrc
评估替换$()
?
另外,一个人如何谷歌搜索一下这种情况?我尝试用谷歌搜索“bashrc 替换”、“bashrc 惰性替换”和其他关键短语,但我没有找到任何我认为应该是一个足够常见的问题来查找信息的内容。