I、可执行命令
Bash下的可执行命令分为四类:
1. Aliases
these are nicknames for a command with some options. They are defined in the shell’s initialization file (~/.bashrc for bash).
$ alias #查看所有定义的别名
$ alias -p #查看定义别名的格式
2. Functions
they are snippets of shell code given a name. Like aliases, they are defined in the shell’s initialization file.
$ declare -f #查看所有定义的函数
3. Builtins
bash内置命令,不需要另外启动子进程来执行,所以所有的操作都会影响当前bash
$ help #查看所有的内置命令及其启用情况
4. External commands
they are independent of the shell,shell executes external programs by looking them up in the executable search path。
II、执行顺序
man bash #COMMAND EXECUTION
III、常用相关命令
# type (buildin)
# Display information about command type, 查看一个命令属于哪一类
$ type -t cmd
# compgen (buildin)
# Display possible completions depending on the options
$ compgen -c # will list all the commands you could run.
$ compgen -a # will list all the aliases you could run.
$ compgen -b # will list all the built-ins you could run.
$ compgen -k # will list all the keywords you could run.
$ compgen -A function # will list all the functions you could run.
$ compgen -A function -abck # will list all the above in one go.
# 查看所有的外部命令
case "$PATH" in
(*[!:]:) PATH="$PATH:" ;;
esac
set -f; IFS=:
for dir in $PATH; do
set +f
[ -z "$dir" ] && dir="."
for file in "$dir"/*; do
if [ -x "$file" ] && ! [ -d "$file" ]; then
printf '%s = %s\n' "${file##*/}" "$file"
fi
done
done