我正在编写一个 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