小编Jay*_*son的帖子

Bash:在变量中使用别名

我正在编写一个 bash 脚本,它将每个参数作为命令运行。这适用于 my 中的命令PATH,但不适用于别名。我可以在脚本中直接调用别名,但不能调用作为参数传递的别名。

问题(我假设)是别名在变量之前扩展。有没有办法从变量运行别名?

示例脚本:

#!/bin/bash
# File: runall

shopt -s expand_aliases
source ~/.aliases

while (( "$#" )); do
    $1
    shift
done
Run Code Online (Sandbox Code Playgroud)

runall "echo test"工作,但runall "myalias"runall: line 8: myalias: command not found

bash alias

11
推荐指数
1
解决办法
6345
查看次数

标签 统计

alias ×1

bash ×1