1 This file is help.def, from which is created help.c.
2 It implements the builtin "help" in Bash.
4 Copyright (C) 1987-2003 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 2, 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, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
25 $FUNCTION help_builtin
26 $DEPENDS_ON HELP_BUILTIN
27 $SHORT_DOC help [-s] [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. The -s option
31 restricts the output for each builtin command matching PATTERN to
32 a short usage synopsis.
37 #if defined (HELP_BUILTIN)
40 #if defined (HAVE_UNISTD_H)
42 # include <sys/types.h>
51 #include "../bashintl.h"
54 #include "../builtins.h"
55 #include "../pathexp.h"
57 #include "bashgetopt.h"
59 #include <glob/strmatch.h>
60 #include <glob/glob.h>
66 static void show_builtin_command_help __P((void));
67 static void show_longdoc __P((int));
69 /* Print out a list of the known functions in the shell, and what they do.
70 If LIST is supplied, print out the list which matches for each pattern
78 int plen, match_found, sflag;
81 reset_internal_getopt ();
82 while ((i = internal_getopt (list, "s")) != -1)
98 show_shell_version (0);
99 show_builtin_command_help ();
100 return (EXECUTION_SUCCESS);
103 /* We should consider making `help bash' do something. */
105 if (glob_pattern_p (list->word->word))
108 printf (_("Shell commands matching keywords `"));
110 printf (_("Shell commands matching keyword `"));
111 print_word_list (list, ", ");
115 for (match_found = 0, pattern = ""; list; list = list->next)
117 pattern = list->word->word;
118 plen = strlen (pattern);
120 for (i = 0; name = shell_builtins[i].name; i++)
123 if ((strncmp (pattern, name, plen) == 0) ||
124 (strmatch (pattern, name, FNMATCH_EXTFLAG) != FNM_NOMATCH))
126 printf ("%s: %s\n", name, shell_builtins[i].short_doc);
136 if (match_found == 0)
138 builtin_error (_("no help topics match `%s'. Try `help help' or `man -k %s' or `info %s'."), pattern, pattern, pattern);
139 return (EXECUTION_FAILURE);
143 return (EXECUTION_SUCCESS);
146 /* By convention, enforced by mkbuiltins.c, if separate help files are being
147 used, the long_doc array contains one string -- the full pathname of the
148 help file for this builtin. */
157 doc = shell_builtins[i].long_doc;
159 if (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL)
161 fd = open (doc[0], O_RDONLY);
164 builtin_error (_("%s: cannot open: %s"), doc[0], strerror (errno));
167 zcatfd (fd, 1, doc[0]);
171 for (j = 0; doc[j]; j++)
172 printf ("%*s%s\n", BASE_INDENT, " ", _(doc[j]));
176 show_builtin_command_help ()
182 _("These shell commands are defined internally. Type `help' to see this list.\n\
183 Type `help name' to find out more about the function `name'.\n\
184 Use `info bash' to find out more about the shell in general.\n\
185 Use `man -k' or `info' to find out more about commands not in this list.\n\
187 A star (*) next to a name means that the command is disabled.\n\
190 for (i = 0; i < num_shell_builtins; i++)
193 blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
194 strncpy (blurb + 1, shell_builtins[i].short_doc, 34);
196 printf ("%s", blurb);
201 for (j = strlen (blurb); j < 35; j++)
207 #endif /* HELP_BUILTIN */