linux - bash 函数与别名冲突

标签 linux bash sh

在 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/

相关文章:

从 stdin 读取时,python 交互模式不起作用

linux - 如何在双引号内执行 Linux shell 变量?

c -/bin/sh依赖哪些POSIX系统接口(interface)?

linux - 如何为给定路径创建文件夹结构和文件

Android - USB 开放附件模式错误

c++ - main() 首先在这里定义

python - 通过 subprocess.call 向 localhost 发出命令

linux - 从 Linux/Windows 编译 Mac

java - 如何找到 Java 代码库中的所有构造函数?

bash - 通过远程 ssh 运行完整命令