2 Main file for attrib shell level 2 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellLevel2CommandsLib.h"
13 Print out each environment variable registered with the Shell 2.0 GUID.
15 If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.
17 @retval STATUS_SUCCESS the printout was sucessful
18 @return any return code from GetNextVariableName except EFI_NOT_FOUND
21 PrintAllShellEnvVars (
26 CONST CHAR16
*ConstEnvNameList
;
28 ConstEnvNameList
= gEfiShellProtocol
->GetEnv (NULL
);
29 if (ConstEnvNameList
== NULL
) {
30 return (SHELL_SUCCESS
);
33 while (*ConstEnvNameList
!= CHAR_NULL
) {
34 Value
= gEfiShellProtocol
->GetEnv (ConstEnvNameList
);
35 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, ConstEnvNameList
, Value
);
36 ConstEnvNameList
+= StrLen (ConstEnvNameList
)+1;
39 return (SHELL_SUCCESS
);
42 STATIC CONST SHELL_PARAM_ITEM SetParamList
[] = {
49 Function for 'set' command.
51 @param[in] ImageHandle Handle to the Image (NULL if Internal).
52 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
57 IN EFI_HANDLE ImageHandle
,
58 IN EFI_SYSTEM_TABLE
*SystemTable
63 CONST CHAR16
*KeyName
;
66 SHELL_STATUS ShellStatus
;
69 ShellStatus
= SHELL_SUCCESS
;
72 // initialize the shell lib (we must be in non-auto-init...)
74 Status
= ShellInitialize ();
75 ASSERT_EFI_ERROR (Status
);
78 // Make sure globals are good...
80 Status
= CommandInit ();
81 ASSERT_EFI_ERROR (Status
);
84 // parse the command line
86 Status
= ShellCommandLineParse (SetParamList
, &Package
, &ProblemParam
, TRUE
);
87 if (EFI_ERROR (Status
)) {
88 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
89 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"set", ProblemParam
);
90 FreePool (ProblemParam
);
91 return (SHELL_INVALID_PARAMETER
);
99 if (ShellCommandLineGetFlag (Package
, L
"-?")) {
101 } else if (ShellCommandLineGetRawValue (Package
, 3) != NULL
) {
102 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"set");
103 ShellStatus
= SHELL_INVALID_PARAMETER
;
104 } else if ((ShellCommandLineGetRawValue (Package
, 1) != NULL
) && ShellCommandLineGetFlag (Package
, L
"-d")) {
105 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"set");
106 ShellStatus
= SHELL_INVALID_PARAMETER
;
107 } else if (ShellCommandLineGetFlag (Package
, L
"-d")) {
109 // delete a environment variable
111 KeyName
= ShellCommandLineGetValue (Package
, L
"-d");
112 if (KeyName
== NULL
) {
113 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"set", L
"-d");
114 ShellStatus
= SHELL_INVALID_PARAMETER
;
116 Status
= ShellSetEnvironmentVariable (KeyName
, L
"", ShellCommandLineGetFlag (Package
, L
"-v"));
117 if (EFI_ERROR (Status
)) {
118 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SET_ND
), gShellLevel2HiiHandle
, L
"set", KeyName
);
119 ShellStatus
= SHELL_DEVICE_ERROR
;
122 } else if (ShellCommandLineGetRawValue (Package
, 1) == NULL
) {
124 // print out all current environment variables
126 return (PrintAllShellEnvVars ());
129 // we are either printing one or assigning one
131 KeyName
= ShellCommandLineGetRawValue (Package
, 1);
132 Value
= ShellCommandLineGetRawValue (Package
, 2);
133 if ((KeyName
!= NULL
) && (Value
!= NULL
)) {
137 Status
= ShellSetEnvironmentVariable (KeyName
, Value
, ShellCommandLineGetFlag (Package
, L
"-v"));
138 if (EFI_ERROR (Status
)) {
139 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SET_ERROR_SET
), gShellLevel2HiiHandle
, L
"set", KeyName
);
140 ShellStatus
= (SHELL_STATUS
)(Status
& (~MAX_BIT
));
143 if (KeyName
!= NULL
) {
145 // print out value for this one only.
147 Value
= ShellGetEnvironmentVariable (KeyName
);
149 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SET_NF
), gShellLevel2HiiHandle
, L
"set", KeyName
);
150 ShellStatus
= SHELL_SUCCESS
;
152 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, KeyName
, Value
);
153 ShellStatus
= SHELL_SUCCESS
;
163 // free the command line package
165 ShellCommandLineFreeVarList (Package
);
167 return (ShellStatus
);