What are commands to find shell keywords, built in functions and user defined functions?

5

2

I was discussing with my friend on how the commands are parsed in the shell, and he told me that bash searches the command in following order

  1. List of aliases
  2. List of shell keywords
  3. List of user defined functions
  4. List of shell built in functions
  5. List of directories specified in the PATH variable , from left to right.

I know aliases can be found by issuing the "alias" command. PATH variable contents can be found using "echo $PATH" command.

Can you please tell me which commands do I need to use to

  1. list all shell keywords
  2. list all user defined functions
  3. list all shell built in functions

Thanks.

Forever Learner

Posted 2013-01-30T11:22:41.940

Reputation: 305

Answers

3

list all shell keywords

Consult your shell's manual for that. "Keyword" is a little ambiguous—for Bash, see the defined builtins below, or consider looking at the shell variables, special parameters, or the index of shell reserved words.

list all user defined functions

In Bash (and Zsh, and probably others), you can use typeset -f to list all functions.

list all shell built in functions

The Bash Reference Manual gives you a list of:

In OS X you can also check out the manpage at man builtin for a comparison between builtins available in different shells. I'm not sure if this is available in GNU/Linux.

slhck

Posted 2013-01-30T11:22:41.940

Reputation: 182 472

+1.Thanks for elaboration. I checked and man builtins worked in GNU/Linux/. Also from other post I found that man bash | grep -10 RESERVED and enable are useful for reserved words and builtins respectively. – Forever Learner – 2013-02-01T21:08:00.590