传递参数的别名在bash [英] Passing argument to alias in bash

查看:280
本文介绍了传递参数的别名在bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能做到以下几点:

我要运行以下命令:

 的MongoDB斌/的mongod

在我的.bash_profile我有

 别名=./path/to/mongodb/$1


解决方案

这是别名将扩大到其重新presents字符串。其扩建后的别名后的内容会出现,而无需成为或能为显式参数传递(例如 $ 1 )。

  $别名富='/路径/要/酒吧
$ foo的一些ARGS

将得到扩大到

  $ /路径/要/酒吧一些ARGS

如果你想使用显式参数,你需要使用函数

  $ foo的(){/路径/要/酒吧$ @固定ARGS; }
$ foo的ABC 123

因为如果你做了

将被执行

  $ /路径/要/条ABC 123固定ARGS

要取消定义别名:

  unalias富

要取消定义的函数:

 取消设置-f富

要看到的类型和定义(每个定义的别名,关键字,功能,内置或可执行文件):

 键入-a富

还是只有类型(最高precedence发生):

 键入-t富

Is it possible to do the following:

I want to run the following:

mongodb bin/mongod

In my bash_profile I have

alias = "./path/to/mongodb/$1"

解决方案

An alias will expand to the string it represents. Anything after the alias will appear after its expansion without needing to be or able to be passed as explicit arguments (e.g. $1).

$ alias foo='/path/to/bar'
$ foo some args

will get expanded to

$ /path/to/bar some args

If you want to use explicit arguments, you'll need to use a function

$ foo () { /path/to/bar "$@" fixed args; }
$ foo abc 123

will be executed as if you had done

$ /path/to/bar abc 123 fixed args

To undefine an alias:

unalias foo

To undefine a function:

unset -f foo

To see the type and definition (for each defined alias, keyword, function, builtin or executable file):

type -a foo

Or type only (for the highest precedence occurrence):

type -t foo

这篇关于传递参数的别名在bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆