问题描述
我以前用CShell() ,这让你做一个别名,它接受一个参数。符号是像
I used to use CShell (csh), which let you make an alias that takes a parameter. The notation was something like
alias junk="mv \\!* ~/.Trash"
在猛砸这似乎并没有工作。鉴于Bash有实用功能众多,我认为这一个已经实现,但我不知道怎么样。
In Bash this does not seem to work. Given that Bash has a multitude of useful features, I would assume that this one has been implemented but I am wondering how.
推荐答案
猛砸别名不直接接受参数。你必须创建一个函数和别名。
Bash alias does not directly accept parameters. You will have to create a function and alias that.
别名
不接受参数,但它可以别名,做一个函数。例如:
alias
does not accept parameters but it can alias a function that does. For example:
myfunction() {
#do things with parameters like $1 such as
mv $1 $1.bak
cp $2 $1
}
alias myname=myfunction
顺便说一句,在你的的.bashrc
等文件中定义Bash函数都可以作为你的shell命令之内。因此,例如,你可以这样调用前面的函数
By the way, Bash functions defined in your .bashrc
and other files are available as commands within your shell. So for instance you can call the earlier function like this
$ myfunction original.conf my.conf
这篇关于使得bash别名需要的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!