在列出系统上所有已定义的函数时,每个函数的名称都带有declare -f前缀
bash4.3 declare -F | head
declare -f __expand_tilde_by_ref
declare -f __get_cword_at_cursor_by_ref
declare -f __git_eread
...作为概念证明,我尝试将函数定义为:
bash4.3 declare -f 'count() { ls -1 | wc -l; } '
bash4.3 declare -F | grep -w count
bash4.3 count() { ls -1 | wc -l; }
bash4.3 declare -F | grep -w count
declare -f count在上面的输出中,只有定义了没有declare的function时才能识别。我是否正确地理解了declare内置不用于函数声明?
发布于 2020-10-26 06:32:38
这是不合法的。在https://wiki.bash-hackers.org/commands/builtin/declare中,在错误代码表下:
+-------------+--------------------------------------------+
| Exit status | Reason |
+-------------+--------------------------------------------+
| != 0 | Attempting to define a function using `-f` |
+-------------+--------------------------------------------+https://stackoverflow.com/questions/64529421
复制相似问题