我怎样才能让别名叫做当它被称为变量 [英] How I can make alias called when it's called by a variable
本文介绍了我怎样才能让别名叫做当它被称为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我增加了一个别名:
$ alias anyalias="echo kallel"
如果我执行:
$ anyalias
kallel
没有任何问题,它执行回声
命令。
现在,如果我用这种方式定义变量:
Now, if I define a variable in this way:
$ var="anyalias"
,然后用这种方式执行:
and then execute with this way:
$ $var
-ash: anyalias: not found
然后,我得到了一个shell错误。
Then I got a shell error.
我怎样才能让 $ VAR
运行在 anyalias
别名定义的命令?
How I can make $var
running the command defined in the anyalias
alias?
我不是想改变调用方式 $ VAR
。但是我正在寻找改变别名定义或将其导出的方法。
I m not looking to change the way of calling $var
. But I m looking for a way of changing the definition of the alias or export it.
推荐答案
而不是别名考虑使用功能:
Instead of alias consider using function:
anyfunc() { echo "kallel"; }
v=anyfunc
$v
kallel
更安全的是函数调用存储在一个阵列(将存储参数也,如果需要的话):
Safer is to store the call of function in an array (will store arguments also, if needed):
var=(anyfunc)
"${var[@]}"
kallel
这篇关于我怎样才能让别名叫做当它被称为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文