Is there any way to list all the internal commands of a shell. I am using bash shell. if I type echo then bash has internal echo command so internal echo command will be executed( Internal command has more precedence than external command ). Is there any way to list all the internal commands of a shell.
1 Answer
In bash there's compgen -b which list all built-in/internal commands.
All other commands can be found in the folders in the $PATH variable.
Here is a script to list all commands (works best in bash):
printf "\033[7mBuilt-in Commands:\033[0m\n%s\n\n\033[7mExternal Commands:\033[0m\n%s\n" "$(compgen -b)" "$(echo "$PATH" | tr ":" "\n" | xargs -I {} ls -1 {} 2>/dev/null | sort -u)"
helpat an interactive prompt.