我想用类似于(all)type
的选项(follow) 来调用。-f
-a
以下是我的问题:
- 是否有内置的 Bash 来打印如何
bash
执行命令? - 是否有 Linux 实用程序可以打印任何 shell 如何执行命令?
- 我正在使用的以下 shell 函数可以简化吗?
给定以下定义并/usr/local/bin/ls
链接到/usr/bin/ls
:
alias ls="\ls -h --color=auto"
alias lsa="ls -A"
alias lsh="lsa -I'*'"
rcommand lsh
印刷:
alias lsh='lsa -I'\''*'\'''
alias lsa='ls -A'
alias ls='\ls -h --color=auto'
link /usr/local/bin/ls
file /usr/bin/ls
这是我在 .bashrc 文件中定义的 shell 函数:
function rcommand {
declare -r a="${1#\\}"
declare -r b="$(type -t "$a")"
if [[ "$b" == alias && "$a" == "$1" ]]; then
declare -r c="$(command -v "$a")"
echo "$c"
declare -r d="$(echo "$c" | sed "s/^.*='\\\\\\?\(\w\+\).*$/\1/")"
if [[ "$d" == "$a" ]]; then
rcommand "\\$d"
else
rcommand "$d"
fi
elif [[ "$b" == builtin || "$b" == function || "$b" == keyword ]]; then
echo "$b $a"
else
declare -r c="$(declare -F "$a")"
if [[ "$c" == "$a" ]]; then
echo "function $a"
else
declare -r d="$(type -P "$a")"
if [[ -h "$d" ]]; then
echo "link $d"
rcommand "$(readlink "$d")"
elif [[ -e "$d" ]]; then
echo "file $d"
fi
fi
fi
}