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
26 CONST CHAR16
*ConstEnvNameList
;
28 ConstEnvNameList
= gEfiShellProtocol
->GetEnv(NULL
);
29 if (ConstEnvNameList
== NULL
) {
30 return (SHELL_SUCCESS
);
32 while (*ConstEnvNameList
!= CHAR_NULL
){
33 Value
= gEfiShellProtocol
->GetEnv(ConstEnvNameList
);
34 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, ConstEnvNameList
, Value
);
35 ConstEnvNameList
+= StrLen(ConstEnvNameList
)+1;
38 return (SHELL_SUCCESS
);
41 STATIC CONST SHELL_PARAM_ITEM SetParamList
[] = {
48 Function for 'set' command.
50 @param[in] ImageHandle Handle to the Image (NULL if Internal).
51 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
56 IN EFI_HANDLE ImageHandle
,
57 IN EFI_SYSTEM_TABLE
*SystemTable
62 CONST CHAR16
*KeyName
;
65 SHELL_STATUS ShellStatus
;
68 ShellStatus
= SHELL_SUCCESS
;
71 // initialize the shell lib (we must be in non-auto-init...)
73 Status
= ShellInitialize();
74 ASSERT_EFI_ERROR(Status
);
77 // Make sure globals are good...
79 Status
= CommandInit();
80 ASSERT_EFI_ERROR(Status
);
83 // parse the command line
85 Status
= ShellCommandLineParse (SetParamList
, &Package
, &ProblemParam
, TRUE
);
86 if (EFI_ERROR(Status
)) {
87 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
88 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"set", ProblemParam
);
89 FreePool(ProblemParam
);
90 return (SHELL_INVALID_PARAMETER
);
98 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
100 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
101 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"set");
102 ShellStatus
= SHELL_INVALID_PARAMETER
;
103 } else if (ShellCommandLineGetRawValue(Package
, 1) != NULL
&& ShellCommandLineGetFlag(Package
, L
"-d")) {
104 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"set");
105 ShellStatus
= SHELL_INVALID_PARAMETER
;
106 } else if (ShellCommandLineGetFlag(Package
, L
"-d")) {
108 // delete a environment variable
110 KeyName
= ShellCommandLineGetValue(Package
, L
"-d");
111 if (KeyName
== NULL
) {
112 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"set", L
"-d");
113 ShellStatus
= SHELL_INVALID_PARAMETER
;
115 Status
= ShellSetEnvironmentVariable(KeyName
, L
"", ShellCommandLineGetFlag(Package
, L
"-v"));
116 if (EFI_ERROR(Status
)) {
117 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_ND
), gShellLevel2HiiHandle
, L
"set", KeyName
);
118 ShellStatus
= SHELL_DEVICE_ERROR
;
121 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
123 // print out all current environment variables
125 return(PrintAllShellEnvVars());
128 // we are either printing one or assigning one
130 KeyName
= ShellCommandLineGetRawValue(Package
, 1);
131 Value
= ShellCommandLineGetRawValue(Package
, 2);
132 if (KeyName
!= NULL
&& Value
!= NULL
) {
136 Status
= ShellSetEnvironmentVariable(KeyName
, Value
, ShellCommandLineGetFlag(Package
, L
"-v"));
137 if (EFI_ERROR(Status
)) {
138 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_ERROR_SET
), gShellLevel2HiiHandle
, L
"set", KeyName
);
139 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
);