$BUILTIN type
$FUNCTION type_builtin
-$SHORT_DOC type [-all] [-type | -path] [name ...]
+$SHORT_DOC type [-apt] name [name ...]
For each NAME, indicate how it would be interpreted if used as a
command name.
-If the -type flag is used, returns a single word which is one of
+If the -t option is used, returns a single word which is one of
`alias', `keyword', `function', `builtin', `file' or `', if NAME is an
alias, shell reserved word, shell function, shell builtin, disk file,
or unfound, respectively.
-If the -path flag is used, either returns the name of the disk file
-that would be exec'ed, or nothing if -type wouldn't return `file'.
+If the -p flag is used, either returns the name of the disk file
+that would be executed, or nothing if -t would not return `file'.
-If the -all flag is used, displays all of the places that contain an
+If the -a flag is used, displays all of the places that contain an
executable named `file'. This includes aliases and functions, if and
-only if the -path flag is not also used.
+only if the -p flag is not also used.
+
+Type accepts -all, -path, and -type in place of -a, -p, and -t,
+respectively.
$END
-#include <stdio.h>
-#include <sys/types.h>
+#include <config.h>
+
+#include "../bashtypes.h"
#include "../posixstat.h"
+
+#if defined (HAVE_UNISTD_H)
+# include <unistd.h>
+#endif
+
+#include <stdio.h>
+#include "../bashansi.h"
+
#include "../shell.h"
#include "../execute_cmd.h"
#include "common.h"
-extern STRING_INT_ALIST word_token_alist[];
+extern int find_reserved_word ();
/* For each word in LIST, find out what the shell is going to do with
it as a simple command. i.e., which file would this shell use to
builtin
file
*/
+int
type_builtin (list)
WORD_LIST *list;
{
int path_only, type_only, all, verbose;
int successful_finds;
+ if (list == 0)
+ return (EXECUTION_SUCCESS);
+
path_only = type_only = all = 0;
successful_finds = 0;
- if (!list)
- return (EXECUTION_SUCCESS);
-
while (list && *(list->word->word) == '-')
{
char *flag = &(list->word->word[1]);
else
{
bad_option (flag);
- builtin_error ("usage: type [-all | -path | -type ] name [name ...]");
+ builtin_usage ();
return (EX_USAGE);
}
list = list->next;
if (type_only)
verbose = 1;
- else if (!path_only)
+ else if (path_only == 0)
verbose = 2;
else if (path_only)
verbose = 3;
* ALL says whether or not to look for all occurrences of COMMAND, or
* return after finding it once.
*/
+int
describe_command (command, verbose, all)
char *command;
int verbose, all;
{
- int found = 0, i, found_file = 0;
- char *full_path = (char *)NULL;
+ int found, i, found_file;
+ char *full_path;
SHELL_VAR *func;
+#if defined (ALIAS)
+ alias_t *alias;
+#endif
+
+ found = found_file = 0;
+ full_path = (char *)NULL;
#if defined (ALIAS)
/* Command is an alias? */
- ASSOC *alias = find_alias (command);
+ alias = find_alias (command);
if (alias)
{
if (verbose == 1)
- printf ("alias\n");
+ puts ("alias");
else if (verbose == 2)
printf ("%s is aliased to `%s'\n", command, alias->value);
else if (verbose == 4)
if (i >= 0)
{
if (verbose == 1)
- printf ("keyword\n");
+ puts ("keyword");
else if (verbose == 2)
printf ("%s is a shell keyword\n", command);
else if (verbose == 4)
if (func)
{
if (verbose == 1)
- printf ("function\n");
+ puts ("function");
else if (verbose == 2)
{
#define PRETTY_PRINT_FUNC 1
if (find_shell_builtin (command))
{
if (verbose == 1)
- printf ("builtin\n");
+ puts ("builtin");
else if (verbose == 2)
printf ("%s is a shell builtin\n", command);
else if (verbose == 4)
if (f & FS_EXECABLE)
{
if (verbose == 1)
- printf ("file\n");
+ puts ("file");
else if (verbose == 2)
printf ("%s is %s\n", command, command);
else if (verbose == 3 || verbose == 4)
if ((full_path = find_hashed_filename (command)) != (char *)NULL)
{
if (verbose == 1)
- printf ("file\n");
+ puts ("file");
else if (verbose == 2)
printf ("%s is hashed (%s)\n", command, full_path);
else if (verbose == 3 || verbose == 4)
found = 1;
if (verbose == 1)
- printf ("file\n");
+ puts ("file");
else if (verbose == 2)
printf ("%s is %s\n", command, full_path);
else if (verbose == 3 || verbose == 4)