在 bash 脚本文件中定义同名函数之前如何检测别名(该文件将在另一个脚本中获取)?
类似于 bash 中的元编程(如果该名称已被别名占用,是否定义另一个名称函数?)
$ source t.sh
$ alert 'test'
test
$ type alert
alert is a function
alert ()
{
echo -n "$@"
}
$ alias alert='notify-send --urgency=low -i error'
$ source t.sh
bash: t.sh: line 1: syntax error near unexpected token `('
bash: t.sh: line 1: `alert() { echo "$@"; }'
$ type alert
alert is aliased to `notify-send --urgency=low -i error'
$ cat t.sh
alert() { echo "$@"; }
最佳答案
你不需要。默认情况下,别名不会在非交互式 shell 中展开。
关于linux - bash 函数与别名冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20114441/