blob: 6f8471ac31778fb1170cd8ace74b4de9e364474f [file] [log] [blame]
Jari Aaltob72432f1999-02-19 17:11:39 +00001/*
2 * whoami - print out username of current user
3 */
4
Jari Aalto31859422009-01-12 13:36:28 +00005/*
6 Copyright (C) 1999-2009 Free Software Foundation, Inc.
7
8 This file is part of GNU Bash.
9 Bash is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Bash is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Bash. If not, see <http://www.gnu.org/licenses/>.
21*/
22
Jari Aaltob72432f1999-02-19 17:11:39 +000023#include <config.h>
24#include <stdio.h>
25
26#include "builtins.h"
27#include "shell.h"
28#include "bashgetopt.h"
Jari Aalto31859422009-01-12 13:36:28 +000029#include "common.h"
Jari Aaltob72432f1999-02-19 17:11:39 +000030
31whoami_builtin (list)
32 WORD_LIST *list;
33{
34 int opt;
35
36 reset_internal_getopt ();
37 while ((opt = internal_getopt (list, "")) != -1)
38 {
39 switch (opt)
40 {
41 default:
42 builtin_usage ();
43 return (EX_USAGE);
44 }
45 }
46 list = loptend;
47 if (list)
48 {
49 builtin_usage ();
50 return (EX_USAGE);
51 }
52
53 if (current_user.user_name == 0)
54 get_current_user_info ();
55 printf ("%s\n", current_user.user_name);
56 return (EXECUTION_SUCCESS);
57}
58
59char *whoami_doc[] = {
Jari Aalto31859422009-01-12 13:36:28 +000060 "Print user name",
61 "",
62 "Display name of current user.",
Jari Aaltob72432f1999-02-19 17:11:39 +000063 (char *)NULL
64};
65
66struct builtin whoami_struct = {
67 "whoami",
68 whoami_builtin,
69 BUILTIN_ENABLED,
70 whoami_doc,
71 "whoami",
72 0
73};