相关疑难解决方法(0)

为什么函数内的别名不起作用?

请参阅下面的代码:

a()(alias x=echo\ hi;type x;alias;x);a
Run Code Online (Sandbox Code Playgroud)

我在函数中有一个别名,我不想更改外部环境(这就是为什么我使用()而不是{}),即使代码说别名已成功设置,它也不起作用,请检查输出:

x is aliased to `echo hi'
...
alias x='echo hi'
x: command not found
Run Code Online (Sandbox Code Playgroud)

我听说这样做shopt -s expand_aliases可以解决,但不只是它没有任何效果,以及我不能依靠bash,因为我有工作dd-wrtbusyboxash

有人知道这个问题吗?

shell dash alias shell-script function

5
推荐指数
2
解决办法
2061
查看次数

标签 统计

alias ×1

dash ×1

function ×1

shell ×1

shell-script ×1