1 This file is help.def, from which is created help.c.
2 It implements the builtin "help" in Bash.
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 1, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 $FUNCTION help_builtin
26 $DEPENDS_ON HELP_BUILTIN
27 $SHORT_DOC help [pattern ...]
28 Display helpful information about builtin commands. If PATTERN is
29 specified, gives detailed help on all commands matching PATTERN,
30 otherwise a list of the builtins is printed.
35 #if defined (HELP_BUILTIN)
38 #if defined (HAVE_UNISTD_H)
43 #include "../builtins.h"
44 #include "bashgetopt.h"
46 #include <glob/fnmatch.h>
47 #include <glob/glob.h>
49 static void show_builtin_command_help ();
51 /* Print out a list of the known functions in the shell, and what they do.
52 If LIST is supplied, print out the list which matches for each pattern
60 int plen, match_found;
64 show_shell_version (0);
65 show_builtin_command_help ();
66 return (EXECUTION_SUCCESS);
69 /* Placeholder for future options. */
70 reset_internal_getopt ();
71 while ((i = internal_getopt (list, "")) != -1)
82 /* We should consider making `help bash' do something. */
84 if (glob_pattern_p (list->word->word))
86 printf ("Shell commands matching keyword%s `", list->next ? "s" : "");
87 print_word_list (list, ", ");
91 for (match_found = 0, pattern = ""; list; list = list->next)
93 pattern = list->word->word;
94 plen = strlen (pattern);
96 for (i = 0; name = shell_builtins[i].name; i++)
99 if ((strncmp (pattern, name, plen) == 0) ||
100 (fnmatch (pattern, name, 0) != FNM_NOMATCH))
102 printf ("%s: %s\n", name, shell_builtins[i].short_doc);
104 for (j = 0; shell_builtins[i].long_doc[j]; j++)
105 printf (" %s\n", shell_builtins[i].long_doc[j]);
112 if (match_found == 0)
114 builtin_error ("no help topics match `%s'. Try `help help'.", pattern);
115 return (EXECUTION_FAILURE);
119 return (EXECUTION_SUCCESS);
123 show_builtin_command_help ()
129 "These shell commands are defined internally. Type `help' to see this list.\n\
130 Type `help name' to find out more about the function `name'.\n\
131 Use `info bash' to find out more about the shell in general.\n\
133 A star (*) next to a name means that the command is disabled.\n\
136 for (i = 0; i < num_shell_builtins; i++)
139 blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
140 strncpy (blurb + 1, shell_builtins[i].short_doc, 34);
142 printf ("%s", blurb);
147 for (j = strlen (blurb); j < 35; j++)
153 #endif /* HELP_BUILTIN */