我一次又一次地看到Bash在Stack Overflow上使用eval的答案,并且答案得到了抨击,双关语是为了使用这种"邪恶"结构.为什么eval这么邪恶?
如果eval不能安全使用,我应该使用什么呢?
我正在尝试在bash中编写一个函数来访问脚本命令行参数,但是它们被替换为函数的位置参数.如果函数没有显式传递,是否有任何方法可以访问命令行参数?
# Demo function
function stuff {
echo $0 $*
}
# Echo's the name of the script, but no command line arguments
stuff
# Echo's everything I want, but trying to avoid
stuff $*
Run Code Online (Sandbox Code Playgroud)