]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/Shell.c
Roll back check in r15180 which caused the shell always returns EFI_ABORTED no matter...
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.c
index df101a32af0157e16eeac13a085e67e62397796b..41fa78004dcca81646bd377e7655a6506d5a9510 100644 (file)
@@ -2,7 +2,7 @@
   This is THE shell (application)\r
 \r
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
-  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.\r
+  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -244,9 +244,6 @@ UefiMain (
   UINTN                           Size;\r
   EFI_HANDLE                      ConInHandle;\r
   EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *OldConIn;\r
-  UINTN                           ExitDataSize;\r
-  CHAR16                          *ExitData;\r
-  SHELL_STATUS                    ExitStatus;\r
 \r
   if (PcdGet8(PcdShellSupportLevel) > 3) {\r
     return (EFI_UNSUPPORTED);\r
@@ -300,12 +297,6 @@ UefiMain (
   // install our console logger.  This will keep a log of the output for back-browsing\r
   //\r
   Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);\r
-  if(EFI_ERROR (Status)) {\r
-    ExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
-  } else {\r
-    ExitStatus = SHELL_SUCCESS;\r
-  }\r
-       \r
   if (!EFI_ERROR(Status)) {\r
     //\r
     // Enable the cursor to be visible\r
@@ -359,7 +350,10 @@ UefiMain (
     //\r
     // Check the command line\r
     //\r
-    Status = ProcessCommandLine();\r
+    Status = ProcessCommandLine ();\r
+    if (EFI_ERROR (Status)) {\r
+      goto FreeResources;\r
+    }\r
 \r
     //\r
     // If shell support level is >= 1 create the mappings and paths\r
@@ -416,7 +410,7 @@ UefiMain (
     // Display the mapping\r
     //\r
     if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {\r
-      Status = RunCommand(L"map", NULL);\r
+      Status = RunCommand(L"map");\r
       ASSERT_EFI_ERROR(Status);\r
     }\r
 \r
@@ -482,11 +476,7 @@ UefiMain (
         //\r
         // process the startup script or launch the called app.\r
         //\r
-        Status = DoStartupScript(\r
-                  ShellInfoObject.ImageDevPath,\r
-                  ShellInfoObject.FileDevPath,\r
-                  &ExitStatus\r
-                  );\r
+        Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r
       }\r
 \r
       if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
@@ -506,6 +496,7 @@ UefiMain (
           // Reset page break back to default.\r
           //\r
           ShellInfoObject.PageBreakEnabled        = PcdGetBool(PcdShellPageBreakDefault);\r
+          ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r
           ShellInfoObject.ConsoleInfo->Enabled    = TRUE;\r
           ShellInfoObject.ConsoleInfo->RowCounter = 0;\r
 \r
@@ -519,7 +510,6 @@ UefiMain (
           //\r
           Status = DoShellPrompt();\r
         } while (!ShellCommandGetExit());\r
-        ExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();\r
       }\r
       if (OldConIn != NULL && ConInHandle != NULL) {\r
         CloseSimpleTextInOnFile (gST->ConIn);\r
@@ -591,33 +581,10 @@ FreeResources:
     DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);\r
   }\r
 \r
-  if (!EFI_ERROR (Status)) {\r
-    // If the command exited with an error, we pass this error out in the ExitData\r
-    // so that it can be retrieved by the EfiShellExecute function (which may\r
-    // start the shell with gBS->StartImage)\r
-    if (ExitStatus != SHELL_SUCCESS) {\r
-      // Allocate a buffer for exit data to pass to gBS->Exit().\r
-      // This buffer will contain the empty string immediately followed by\r
-      // the shell's exit status. (The empty string is required by the UEFI spec)\r
-      ExitDataSize = (sizeof (CHAR16) + sizeof (SHELL_STATUS));\r
-      ExitData = AllocatePool (ExitDataSize);\r
-      if (ExitData == NULL) {\r
-        return EFI_OUT_OF_RESOURCES;\r
-      }\r
-      ExitData[0] = '\0';\r
-      // Use CopyMem to avoid alignment faults\r
-      CopyMem ((ExitData + 1), &ExitStatus, sizeof (ExitStatus));\r
-\r
-      gBS->Exit (ImageHandle, EFI_ABORTED, ExitDataSize, ExitData);\r
-\r
-      ASSERT (FALSE);\r
-      return EFI_SUCCESS;\r
-    } else {\r
-      return EFI_SUCCESS;\r
-    }\r
-  } else {\r
-    return Status;\r
+  if (ShellCommandGetExit()) {\r
+    return ((EFI_STATUS)ShellCommandGetExitCode());\r
   }\r
+  return (Status);\r
 }\r
 \r
 /**\r
@@ -832,9 +799,13 @@ ProcessCommandLine(
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = FALSE;\r
   ShellInfoObject.ShellInitSettings.Delay = 5;\r
 \r
-  // Start LoopVar at 1 to ignore Argv[0] which is the name of this binary\r
-  // (probably "Shell.efi")\r
-  for (LoopVar = 1 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
+  //\r
+  // Start LoopVar at 0 to parse only optional arguments at Argv[0]\r
+  // and parse other parameters from Argv[1].  This is for use case that\r
+  // UEFI Shell boot option is created, and OptionalData is provided\r
+  // that starts with shell command-line options.\r
+  //\r
+  for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
     CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar];\r
     if (UnicodeCollation->StriColl (\r
                             UnicodeCollation,\r
@@ -922,7 +893,14 @@ ProcessCommandLine(
         );\r
       return EFI_INVALID_PARAMETER;\r
     } else {\r
-      ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(CurrentArg));\r
+      //\r
+      // First argument should be Shell.efi image name\r
+      //\r
+      if (LoopVar == 0) {\r
+        continue;\r
+      }\r
+\r
+      ShellInfoObject.ShellInitSettings.FileName = AllocateCopyPool(StrSize(CurrentArg), CurrentArg);\r
       if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
@@ -930,12 +908,10 @@ ProcessCommandLine(
       // We found `file-name`.\r
       //\r
       ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;\r
-\r
-      StrCpy (ShellInfoObject.ShellInitSettings.FileName, CurrentArg);\r
       LoopVar++;\r
 \r
       // Add `file-name-options`\r
-      for ( ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
+      for (Size = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
         ASSERT((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));\r
         StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r
                     &Size,\r
@@ -973,16 +949,13 @@ ProcessCommandLine(
   @param ImagePath              the path to the image for shell.  first place to look for the startup script\r
   @param FilePath               the path to the file for shell.  second place to look for the startup script.\r
 \r
-  @param[out] ExitStatus      The exit code of the script. Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS           the variable is initialized.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 DoStartupScript(\r
-  IN  EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
-  OUT SHELL_STATUS             *ExitStatus\r
+  IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
+  IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
@@ -1012,12 +985,12 @@ DoStartupScript(
     if (FileStringPath == NULL) {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
-    StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName);\r
+    StrnCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName, NewSize/sizeof(CHAR16) -1);\r
     if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
-      StrCat(FileStringPath, L" ");\r
-      StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions);\r
+      StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
+      StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
     }\r
-    Status = RunCommand(FileStringPath, ExitStatus);\r
+    Status = RunCommand(FileStringPath);\r
     FreePool(FileStringPath);\r
     return (Status);\r
 \r
@@ -1094,13 +1067,7 @@ DoStartupScript(
   // If we got a file, run it\r
   //\r
   if (!EFI_ERROR(Status) && FileHandle != NULL) {\r
-    Status = RunScriptFile (\r
-              mStartupScript,\r
-              FileHandle,\r
-              L"",\r
-              ShellInfoObject.NewShellParametersProtocol,\r
-              ExitStatus\r
-              );\r
+    Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);\r
     ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r
   } else {\r
     FileStringPath = ShellFindFilePath(mStartupScript);\r
@@ -1111,13 +1078,7 @@ DoStartupScript(
       Status = EFI_SUCCESS;\r
       ASSERT(FileHandle == NULL);\r
     } else {\r
-      Status = RunScriptFile(\r
-                FileStringPath,\r
-                NULL,\r
-                L"",\r
-                ShellInfoObject.NewShellParametersProtocol,\r
-                ExitStatus\r
-                );\r
+      Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);\r
       FreePool(FileStringPath);\r
     }\r
   }\r
@@ -1182,7 +1143,7 @@ DoShellPrompt (
   //\r
   if (!EFI_ERROR (Status)) {\r
     CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r
-    Status = RunCommand(CmdLine, NULL);\r
+    Status = RunCommand(CmdLine);\r
     }\r
 \r
   //\r
@@ -1232,9 +1193,8 @@ AddLineToCommandHistory(
 \r
   Node = AllocateZeroPool(sizeof(BUFFER_LIST));\r
   ASSERT(Node != NULL);\r
-  Node->Buffer = AllocateZeroPool(StrSize(Buffer));\r
+  Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);\r
   ASSERT(Node->Buffer != NULL);\r
-  StrCpy(Node->Buffer, Buffer);\r
 \r
   InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
 }\r
@@ -1265,11 +1225,117 @@ ShellConvertAlias(
     return (EFI_SUCCESS);\r
   }\r
   FreePool(*CommandString);\r
-  *CommandString = AllocateZeroPool(StrSize(NewString));\r
+  *CommandString = AllocateCopyPool(StrSize(NewString), NewString);\r
   if (*CommandString == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrCpy(*CommandString, NewString);\r
+  return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+  Parse for the next instance of one string within another string. Can optionally make sure that \r
+  the string was not escaped (^ character) per the shell specification.\r
+\r
+  @param[in] SourceString             The string to search within\r
+  @param[in] FindString               The string to look for\r
+  @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FindNextInstance(\r
+  IN CONST CHAR16   *SourceString,\r
+  IN CONST CHAR16   *FindString,\r
+  IN CONST BOOLEAN  CheckForEscapeCharacter\r
+  )\r
+{\r
+  CHAR16 *Temp;\r
+  if (SourceString == NULL) {\r
+    return (NULL);\r
+  }\r
+  Temp = StrStr(SourceString, FindString);\r
+\r
+  //\r
+  // If nothing found, or we dont care about escape characters\r
+  //\r
+  if (Temp == NULL || !CheckForEscapeCharacter) {\r
+    return (Temp);\r
+  }\r
+\r
+  //\r
+  // If we found an escaped character, try again on the remainder of the string\r
+  //\r
+  if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r
+    return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r
+  }\r
+\r
+  //\r
+  // we found the right character\r
+  //\r
+  return (Temp);\r
+}\r
+\r
+/**\r
+  This function will eliminate unreplaced (and therefore non-found) environment variables.\r
+\r
+  @param[in,out] CmdLine   The command line to update.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StripUnreplacedEnvironmentVariables(\r
+  IN OUT CHAR16 *CmdLine\r
+  )\r
+{\r
+  CHAR16 *FirstPercent;\r
+  CHAR16 *FirstQuote;\r
+  CHAR16 *SecondPercent;\r
+  CHAR16 *SecondQuote;\r
+  CHAR16 *CurrentLocator;\r
+\r
+  for (CurrentLocator = CmdLine ; CurrentLocator != NULL ; ) {\r
+    FirstQuote = FindNextInstance(CurrentLocator, L"\"", TRUE);\r
+    FirstPercent = FindNextInstance(CurrentLocator, L"%", TRUE);\r
+    SecondPercent = FirstPercent!=NULL?FindNextInstance(FirstPercent+1, L"%", TRUE):NULL;\r
+    if (FirstPercent == NULL || SecondPercent == NULL) {\r
+      //\r
+      // If we ever dont have 2 % we are done.\r
+      //\r
+      break;\r
+    }\r
+\r
+    if (FirstQuote < FirstPercent) {\r
+      SecondQuote = FirstQuote!= NULL?FindNextInstance(FirstQuote+1, L"\"", TRUE):NULL;\r
+      //\r
+      // Quote is first found\r
+      //\r
+\r
+      if (SecondQuote < FirstPercent) {\r
+        //\r
+        // restart after the pair of "\r
+        //\r
+        CurrentLocator = SecondQuote + 1;\r
+      } else /* FirstPercent < SecondQuote */{\r
+        //\r
+        // Restart on the first percent\r
+        //\r
+        CurrentLocator = FirstPercent;\r
+      }\r
+      continue;\r
+    }\r
+    ASSERT(FirstPercent < FirstQuote);\r
+    if (SecondPercent < FirstQuote) {\r
+      FirstPercent[0] = L'\"';\r
+      SecondPercent[0] = L'\"';\r
+\r
+      //\r
+      // We need to remove from FirstPercent to SecondPercent\r
+      //\r
+      CopyMem(FirstPercent + 1, SecondPercent, StrSize(SecondPercent));\r
+      CurrentLocator = FirstPercent + 2;\r
+      continue;\r
+    }\r
+    ASSERT(FirstQuote < SecondPercent);\r
+    CurrentLocator = FirstQuote;\r
+  }\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -1295,7 +1361,6 @@ ShellConvertVariables (
   CHAR16              *NewCommandLine1;\r
   CHAR16              *NewCommandLine2;\r
   CHAR16              *Temp;\r
-  CHAR16              *Temp2;\r
   UINTN               ItemSize;\r
   CHAR16              *ItemTemp;\r
   SCRIPT_FILE         *CurrentScriptFile;\r
@@ -1356,7 +1421,7 @@ ShellConvertVariables (
   //\r
   // now do the replacements...\r
   //\r
-  NewCommandLine1 = AllocateZeroPool(NewSize);\r
+  NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine);\r
   NewCommandLine2 = AllocateZeroPool(NewSize);\r
   ItemTemp        = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));\r
   if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {\r
@@ -1365,16 +1430,15 @@ ShellConvertVariables (
     SHELL_FREE_NON_NULL(ItemTemp);\r
     return (NULL);\r
   }\r
-  StrCpy(NewCommandLine1, OriginalCommandLine);\r
   for (MasterEnvList = EfiShellGetEnv(NULL)\r
-    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL\r
+    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
     ;  MasterEnvList += StrLen(MasterEnvList) + 1\r
    ){\r
-    StrCpy(ItemTemp, L"%");\r
-    StrCat(ItemTemp, MasterEnvList);\r
-    StrCat(ItemTemp, L"%");\r
+    StrnCpy(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1);\r
+    StrnCat(ItemTemp, MasterEnvList, ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));\r
+    StrnCat(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));\r
     ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);\r
-    StrCpy(NewCommandLine1, NewCommandLine2);\r
+    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
   }\r
   if (CurrentScriptFile != NULL) {\r
     for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r
@@ -1382,52 +1446,20 @@ ShellConvertVariables (
       ;  AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
    ){\r
     ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r
-    StrCpy(NewCommandLine1, NewCommandLine2);\r
+    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
     }\r
 \r
     //\r
     // Remove non-existant environment variables in scripts only\r
     //\r
-    for (Temp = NewCommandLine1 ; Temp != NULL ; ) {\r
-      Temp = StrStr(Temp, L"%");\r
-      if (Temp == NULL) {\r
-        break;\r
-      }\r
-      while (*(Temp - 1) == L'^') {\r
-        Temp = StrStr(Temp + 1, L"%");\r
-        if (Temp == NULL) {\r
-          break;\r
-       }\r
-      }\r
-      if (Temp == NULL) {\r
-        break;\r
-      }\r
-      \r
-      Temp2 = StrStr(Temp + 1, L"%");\r
-      if (Temp2 == NULL) {\r
-        break;\r
-      }\r
-      while (*(Temp2 - 1) == L'^') {\r
-        Temp2 = StrStr(Temp2 + 1, L"%");\r
-        if (Temp2 == NULL) {\r
-          break;\r
-        }\r
-      }\r
-      if (Temp2 == NULL) {\r
-        break;\r
-      }\r
-      \r
-      Temp2++;\r
-      CopyMem(Temp, Temp2, StrSize(Temp2));\r
-    }\r
-\r
+    StripUnreplacedEnvironmentVariables(NewCommandLine1);\r
   }\r
 \r
   //\r
   // Now cleanup any straggler intentionally ignored "%" characters\r
   //\r
   ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);\r
-  StrCpy(NewCommandLine1, NewCommandLine2);\r
+  StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
   \r
   FreePool(NewCommandLine2);\r
   FreePool(ItemTemp);\r
@@ -1442,9 +1474,6 @@ ShellConvertVariables (
   @param[in] StdIn          The pointer to the Standard input.\r
   @param[in] StdOut         The pointer to the Standard output.\r
 \r
-  @param[out] ExitStatus      The exit code of the last command in the pipeline.\r
-                              Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS       The split command is executed successfully.\r
   @retval other             Some error occurs when executing the split command.\r
 **/\r
@@ -1453,8 +1482,7 @@ EFIAPI
 RunSplitCommand(\r
   IN CONST CHAR16             *CmdLine,\r
   IN       SHELL_FILE_HANDLE  *StdIn,\r
-  IN       SHELL_FILE_HANDLE  *StdOut,\r
-  OUT      SHELL_STATUS       *ExitStatus\r
+  IN       SHELL_FILE_HANDLE  *StdOut\r
   )\r
 {\r
   EFI_STATUS        Status;\r
@@ -1508,7 +1536,7 @@ RunSplitCommand(
   ASSERT(Split->SplitStdOut != NULL);\r
   InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);\r
 \r
-  Status = RunCommand(OurCommandLine, NULL);\r
+  Status = RunCommand(OurCommandLine);\r
 \r
   //\r
   // move the output from the first to the in to the second.\r
@@ -1523,7 +1551,7 @@ RunSplitCommand(
   ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);\r
 \r
   if (!EFI_ERROR(Status)) {\r
-    Status = RunCommand(NextCommandLine, ExitStatus);\r
+    Status = RunCommand(NextCommandLine);\r
   }\r
 \r
   //\r
@@ -1674,10 +1702,12 @@ GetOperationType(
   }\r
 \r
   //\r
-  // Test for file system change request.  anything ending with : and cant have spaces.\r
+  // Test for file system change request.  anything ending with first : and cant have spaces.\r
   //\r
   if (CmdName[(StrLen(CmdName)-1)] == L':') {\r
-    if (StrStr(CmdName, L" ") != NULL) {\r
+    if ( StrStr(CmdName, L" ") != NULL \r
+      || StrLen(StrStr(CmdName, L":")) > 1\r
+      ) {\r
       return (Unknown_Invalid);\r
     }\r
     return (File_Sys_Change);\r
@@ -1759,7 +1789,7 @@ IsValidSplit(
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
     TempWalker = (CHAR16*)Temp;\r
-    GetNextParameter(&TempWalker, &FirstParameter);\r
+    GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine));\r
 \r
     if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
@@ -1815,9 +1845,7 @@ VerifySplit(
 /**\r
   Process a split based operation.\r
 \r
-  @param[in] CmdLine      Pointer to the command line to process\r
-  @param[out] ExitStatus  The exit status of the command. Ignored if NULL.\r
-                          Invalid if this function returns an error.\r
+  @param[in] CmdLine    pointer to the command line to process\r
 \r
   @retval EFI_SUCCESS   The operation was successful\r
   @return               an error occured.\r
@@ -1825,8 +1853,7 @@ VerifySplit(
 EFI_STATUS\r
 EFIAPI\r
 ProcessNewSplitCommandLine(\r
-  IN CONST CHAR16       *CmdLine,\r
-  OUT      SHELL_STATUS *ExitStatus\r
+  IN CONST CHAR16 *CmdLine\r
   )\r
 {\r
   SPLIT_LIST                *Split;\r
@@ -1847,14 +1874,9 @@ ProcessNewSplitCommandLine(
   }\r
 \r
   if (Split == NULL) {\r
-    Status = RunSplitCommand(CmdLine, NULL, NULL, ExitStatus);\r
+    Status = RunSplitCommand(CmdLine, NULL, NULL);\r
   } else {\r
-    Status = RunSplitCommand(\r
-              CmdLine,\r
-              Split->SplitStdIn,\r
-              Split->SplitStdOut,\r
-              ExitStatus\r
-              );\r
+    Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r
   }\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r
@@ -1927,7 +1949,7 @@ DoHelpUpdate(
   Walker = *CmdLine;\r
   while(Walker != NULL && *Walker != CHAR_NULL) {\r
     LastWalker = Walker;\r
-    GetNextParameter(&Walker, &CurrentParameter);\r
+    GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine));\r
     if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
       LastWalker[0] = L' ';\r
       LastWalker[1] = L' ';\r
@@ -1936,8 +1958,12 @@ DoHelpUpdate(
         Status = EFI_OUT_OF_RESOURCES;\r
         break;\r
       }\r
-      StrCpy(NewCommandLine, L"help ");\r
-      StrCat(NewCommandLine, *CmdLine);\r
+\r
+      //\r
+      // We know the space is sufficient since we just calculated it.\r
+      //\r
+      StrnCpy(NewCommandLine, L"help ", 5);\r
+      StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));\r
       SHELL_FREE_NON_NULL(*CmdLine);\r
       *CmdLine = NewCommandLine;\r
       break;\r
@@ -2001,6 +2027,7 @@ ProcessCommandLineToFinal(
   if (EFI_ERROR(Status)) {\r
     return (Status);\r
   }\r
+  ASSERT (*CmdLine != NULL);\r
 \r
   TrimSpaces(CmdLine);\r
 \r
@@ -2029,8 +2056,6 @@ ProcessCommandLineToFinal(
   @param[in] FirstParameter   the first parameter on the command line\r
   @param[in] ParamProtocol    the shell parameters protocol pointer\r
 \r
-  @param[out] ExitStatus      The exit code of the command. Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS     The command was completed.\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
@@ -2039,8 +2064,7 @@ EFIAPI
 RunInternalCommand(\r
   IN CONST CHAR16                   *CmdLine,\r
   IN       CHAR16                   *FirstParameter,\r
-  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
-  OUT      SHELL_STATUS             *ExitStatus OPTIONAL\r
+  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol\r
 )\r
 {\r
   EFI_STATUS                Status;\r
@@ -2048,11 +2072,24 @@ RunInternalCommand(
   CHAR16                    **Argv;\r
   SHELL_STATUS              CommandReturnedStatus;\r
   BOOLEAN                   LastError;\r
+  CHAR16                    *Walker;\r
+  CHAR16                    *NewCmdLine;  \r
+\r
+  NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);\r
+  if (NewCmdLine == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+    if (*Walker == L'^' && *(Walker+1) == L'#') {\r
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+    }\r
+  }\r
 \r
   //\r
   // get the argc and argv updated for internal commands\r
   //\r
-  Status = UpdateArgcArgv(ParamProtocol, CmdLine, &Argv, &Argc);\r
+  Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, &Argv, &Argc);\r
   if (!EFI_ERROR(Status)) {\r
     //\r
     // Run the internal command.\r
@@ -2067,9 +2104,6 @@ RunInternalCommand(
       if (LastError) {\r
         SetLastError(CommandReturnedStatus);\r
       }\r
-      if (ExitStatus != NULL) {\r
-        *ExitStatus = CommandReturnedStatus;\r
-      }\r
 \r
       //\r
       // Pass thru the exitcode from the app.\r
@@ -2113,6 +2147,7 @@ RunInternalCommand(
     Status = EFI_SUCCESS;\r
   }\r
 \r
+  FreePool (NewCmdLine);\r
   return (Status);\r
 }\r
 \r
@@ -2124,9 +2159,6 @@ RunInternalCommand(
   @param[in] FirstParameter   the first parameter on the command line\r
   @param[in] ParamProtocol    the shell parameters protocol pointer\r
 \r
-  @param[out] ExitStatus      The exit code of the command or file.\r
-                              Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS     The command was completed.\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
@@ -2136,11 +2168,11 @@ RunCommandOrFile(
   IN       SHELL_OPERATION_TYPES    Type,\r
   IN CONST CHAR16                   *CmdLine,\r
   IN       CHAR16                   *FirstParameter,\r
-  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
-  OUT      SHELL_STATUS             *ExitStatus\r
+  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol\r
 )\r
 {\r
   EFI_STATUS                Status;\r
+  EFI_STATUS                StartStatus;\r
   CHAR16                    *CommandWithPath;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   SHELL_STATUS              CalleeExitStatus;\r
@@ -2152,12 +2184,7 @@ RunCommandOrFile(
 \r
   switch (Type) {\r
     case   Internal_Command:\r
-      Status = RunInternalCommand(\r
-                CmdLine,\r
-                FirstParameter,\r
-                ParamProtocol,\r
-                &CalleeExitStatus\r
-                );\r
+      Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol);\r
       break;\r
     case   Script_File_Name:\r
     case   Efi_Application:\r
@@ -2192,13 +2219,7 @@ RunCommandOrFile(
       }\r
       switch (Type) {\r
         case   Script_File_Name:\r
-          Status = RunScriptFile (\r
-                    CommandWithPath,\r
-                    NULL,\r
-                    CmdLine,\r
-                    ParamProtocol,\r
-                    &CalleeExitStatus\r
-                    );\r
+          Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);\r
           break;\r
         case   Efi_Application:\r
           //\r
@@ -2218,8 +2239,7 @@ RunCommandOrFile(
             DevPath,\r
             CmdLine,\r
             NULL,\r
-            NULL,\r
-            NULL\r
+            &StartStatus\r
            );\r
 \r
           SHELL_FREE_NON_NULL(DevPath);\r
@@ -2227,7 +2247,7 @@ RunCommandOrFile(
           if(EFI_ERROR (Status)) {\r
             CalleeExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
           } else {\r
-            CalleeExitStatus = SHELL_SUCCESS;\r
+            CalleeExitStatus = (SHELL_STATUS) StartStatus;\r
           }\r
 \r
           //\r
@@ -2252,10 +2272,6 @@ RunCommandOrFile(
 \r
   SHELL_FREE_NON_NULL(CommandWithPath);\r
 \r
-  if (ExitStatus != NULL) {\r
-    *ExitStatus = CalleeExitStatus;\r
-  }\r
-\r
   return (Status);\r
 }\r
 \r
@@ -2267,20 +2283,16 @@ RunCommandOrFile(
   @param[in] FirstParameter   the first parameter on the command line.\r
   @param[in] ParamProtocol    the shell parameters protocol pointer\r
 \r
-  @param[out] ExitStatus      The exit code of the command or file.\r
-                              Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS     The command was completed.\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 SetupAndRunCommandOrFile(\r
-  IN   SHELL_OPERATION_TYPES          Type,\r
-  IN   CHAR16                         *CmdLine,\r
-  IN   CHAR16                         *FirstParameter,\r
-  IN   EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
-  OUT  SHELL_STATUS                   *ExitStatus\r
+  IN SHELL_OPERATION_TYPES          Type,\r
+  IN CHAR16                         *CmdLine,\r
+  IN CHAR16                         *FirstParameter,\r
+  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol\r
 )\r
 {\r
   EFI_STATUS                Status;\r
@@ -2299,13 +2311,8 @@ SetupAndRunCommandOrFile(
   // Now run the command, script, or application\r
   //\r
   if (!EFI_ERROR(Status)) {\r
-    Status = RunCommandOrFile(\r
-              Type,\r
-              CmdLine,\r
-              FirstParameter,\r
-              ParamProtocol,\r
-              ExitStatus\r
-              );\r
+    TrimSpaces(&CmdLine);\r
+    Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol);\r
   }\r
 \r
   //\r
@@ -2330,7 +2337,6 @@ SetupAndRunCommandOrFile(
   command or dispatch an external application.\r
 \r
   @param[in] CmdLine      The command line to parse.\r
-  @param[out] ExitStatus  The exit code of the command. Ignored if NULL.\r
 \r
   @retval EFI_SUCCESS     The command was completed.\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
@@ -2338,8 +2344,7 @@ SetupAndRunCommandOrFile(
 EFI_STATUS\r
 EFIAPI\r
 RunCommand(\r
-  IN CONST CHAR16         *CmdLine,\r
-  OUT      SHELL_STATUS   *ExitStatus\r
+  IN CONST CHAR16   *CmdLine\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -2363,6 +2368,24 @@ RunCommand(
 \r
   TrimSpaces(&CleanOriginal);\r
 \r
+  //\r
+  // NULL out comments (leveraged from RunScriptFileHandle() ).\r
+  // The # character on a line is used to denote that all characters on the same line\r
+  // and to the right of the # are to be ignored by the shell.\r
+  // Afterward, again remove spaces, in case any were between the last command-parameter and '#'.\r
+  //\r
+  for (TempWalker = CleanOriginal; TempWalker != NULL && *TempWalker != CHAR_NULL; TempWalker++) {\r
+    if (*TempWalker == L'^') {\r
+      if (*(TempWalker + 1) == L'#') {\r
+        TempWalker++;\r
+      }\r
+    } else if (*TempWalker == L'#') {\r
+      *TempWalker = CHAR_NULL;\r
+    }\r
+  }\r
+\r
+  TrimSpaces(&CleanOriginal);\r
+\r
   //\r
   // Handle case that passed in command line is just 1 or more " " characters.\r
   //\r
@@ -2381,7 +2404,7 @@ RunCommand(
   // We dont do normal processing with a split command line (output from one command input to another)\r
   //\r
   if (ContainsSplit(CleanOriginal)) {\r
-    Status = ProcessNewSplitCommandLine(CleanOriginal, ExitStatus);\r
+    Status = ProcessNewSplitCommandLine(CleanOriginal);\r
     SHELL_FREE_NON_NULL(CleanOriginal);\r
     return (Status);\r
   } \r
@@ -2395,25 +2418,19 @@ RunCommand(
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
   TempWalker = CleanOriginal;\r
-  GetNextParameter(&TempWalker, &FirstParameter);\r
+  GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal));\r
 \r
   //\r
   // Depending on the first parameter we change the behavior\r
   //\r
   switch (Type = GetOperationType(FirstParameter)) {\r
     case   File_Sys_Change:\r
-      Status = ChangeMappedDrive(CleanOriginal);\r
+      Status = ChangeMappedDrive (FirstParameter);\r
       break;\r
     case   Internal_Command:\r
     case   Script_File_Name:\r
     case   Efi_Application:\r
-      Status = SetupAndRunCommandOrFile(\r
-                Type,\r
-                CleanOriginal,\r
-                FirstParameter,\r
-                ShellInfoObject.NewShellParametersProtocol,\r
-                ExitStatus\r
-                );\r
+      Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);\r
       break;\r
     default:\r
       //\r
@@ -2468,16 +2485,13 @@ IsValidCommandName(
   @param[in] Handle             The handle to the already opened file.\r
   @param[in] Name               The name of the script file.\r
 \r
-  @param[out] ExitStatus      The exit code of the script. Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS           the script completed sucessfully\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 RunScriptFileHandle (\r
-  IN  SHELL_FILE_HANDLE  Handle,\r
-  IN  CONST CHAR16       *Name,\r
-  OUT SHELL_STATUS       *ExitStatus\r
+  IN SHELL_FILE_HANDLE  Handle,\r
+  IN CONST CHAR16       *Name\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -2493,11 +2507,8 @@ RunScriptFileHandle (
   CONST CHAR16        *CurDir;\r
   UINTN               LineCount;\r
   CHAR16              LeString[50];\r
-  SHELL_STATUS        CalleeExitStatus;\r
 \r
   ASSERT(!ShellCommandGetScriptExit());\r
-  \r
-  CalleeExitStatus = SHELL_SUCCESS;\r
 \r
   PreScriptEchoState = ShellCommandGetEchoState();\r
 \r
@@ -2591,15 +2602,17 @@ RunScriptFileHandle (
       ; // conditional increment in the body of the loop\r
   ){\r
     ASSERT(CommandLine2 != NULL);\r
-    StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl);\r
+    StrnCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);\r
 \r
     //\r
     // NULL out comments\r
     //\r
     for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL ; CommandLine3++) {\r
       if (*CommandLine3 == L'^') {\r
-        if (*(CommandLine3+1) == L'#' || *(CommandLine3+1) == L':') {\r
+        if ( *(CommandLine3+1) == L':') {\r
           CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - sizeof(CommandLine3[0]));\r
+        } else if (*(CommandLine3+1) == L'#') {\r
+          CommandLine3++;\r
         }\r
       } else if (*CommandLine3 == L'#') {\r
         *CommandLine3 = CHAR_NULL;\r
@@ -2610,7 +2623,7 @@ RunScriptFileHandle (
       //\r
       // Due to variability in starting the find and replace action we need to have both buffers the same.\r
       //\r
-      StrCpy(CommandLine, CommandLine2);\r
+      StrnCpy(CommandLine, CommandLine2, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);\r
 \r
       //\r
       // Remove the %0 to %9 from the command line (if we have some arguments)\r
@@ -2618,34 +2631,34 @@ RunScriptFileHandle (
       if (NewScriptFile->Argv != NULL) {\r
         switch (NewScriptFile->Argc) {\r
           default:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", NewScriptFile->Argv[9], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", NewScriptFile->Argv[9], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 9:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", NewScriptFile->Argv[8], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", NewScriptFile->Argv[8], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 8:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%7", NewScriptFile->Argv[7], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%7", NewScriptFile->Argv[7], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 7:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%6", NewScriptFile->Argv[6], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%6", NewScriptFile->Argv[6], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 6:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%5", NewScriptFile->Argv[5], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%5", NewScriptFile->Argv[5], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 5:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%4", NewScriptFile->Argv[4], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%4", NewScriptFile->Argv[4], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 4:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%3", NewScriptFile->Argv[3], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%3", NewScriptFile->Argv[3], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 3:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%2", NewScriptFile->Argv[2], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%2", NewScriptFile->Argv[2], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 2:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%1", NewScriptFile->Argv[1], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%1", NewScriptFile->Argv[1], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
           case 1:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%0", NewScriptFile->Argv[0], FALSE, TRUE);\r
+            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%0", NewScriptFile->Argv[0], FALSE, FALSE);\r
             ASSERT_EFI_ERROR(Status);\r
             break;\r
           case 0:\r
@@ -2662,7 +2675,7 @@ RunScriptFileHandle (
       Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", L"\"\"", FALSE, FALSE);\r
       Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);\r
 \r
-      StrCpy(CommandLine2, CommandLine);\r
+      StrnCpy(CommandLine2, CommandLine, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);\r
 \r
       LastCommand = NewScriptFile->CurrentCommand;\r
 \r
@@ -2681,7 +2694,7 @@ RunScriptFileHandle (
             //\r
             PreCommandEchoState = ShellCommandGetEchoState();\r
             ShellCommandSetEchoState(FALSE);\r
-            Status = RunCommand(CommandLine3+1, NULL);\r
+            Status = RunCommand(CommandLine3+1);\r
 \r
             //\r
             // If command was "@echo -off" or "@echo -on" then don't restore echo state\r
@@ -2703,7 +2716,7 @@ RunScriptFileHandle (
               }\r
               ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);\r
             }\r
-            Status = RunCommand(CommandLine3, NULL);\r
+            Status = RunCommand(CommandLine3);\r
           }\r
         }\r
 \r
@@ -2711,8 +2724,7 @@ RunScriptFileHandle (
           //\r
           // ShellCommandGetExitCode() always returns a UINT64\r
           //\r
-          CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();\r
-          UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", CalleeExitStatus);\r
+          UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());\r
           DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
           InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
 \r
@@ -2724,11 +2736,9 @@ RunScriptFileHandle (
           break;\r
         }\r
         if (EFI_ERROR(Status)) {\r
-          CalleeExitStatus = (SHELL_STATUS) Status;\r
           break;\r
         }\r
         if (ShellCommandGetExit()) {\r
-          CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();\r
           break;\r
         }\r
       }\r
@@ -2760,11 +2770,6 @@ RunScriptFileHandle (
   if (ShellCommandGetCurrentScriptFile()==NULL) {\r
     ShellCommandSetEchoState(PreScriptEchoState);\r
   }\r
-\r
-  if (ExitStatus != NULL) {\r
-    *ExitStatus = CalleeExitStatus;\r
-  }\r
-\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -2776,18 +2781,15 @@ RunScriptFileHandle (
   @param[in] CmdLine            the command line to run.\r
   @param[in] ParamProtocol      the shell parameters protocol pointer\r
 \r
-  @param[out] ExitStatus      The exit code of the script. Ignored if NULL.\r
-\r
   @retval EFI_SUCCESS           the script completed sucessfully\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 RunScriptFile (\r
-  IN  CONST CHAR16                   *ScriptPath,\r
-  IN  SHELL_FILE_HANDLE              Handle OPTIONAL,\r
-  IN  CONST CHAR16                   *CmdLine,\r
-  IN  EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
-  OUT SHELL_STATUS                   *ExitStatus\r
+  IN CONST CHAR16                   *ScriptPath,\r
+  IN SHELL_FILE_HANDLE              Handle OPTIONAL,\r
+  IN CONST CHAR16                   *CmdLine,\r
+  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -2814,7 +2816,7 @@ RunScriptFile (
         //\r
         // run it\r
         //\r
-        Status = RunScriptFileHandle(FileHandle, ScriptPath, ExitStatus);\r
+        Status = RunScriptFileHandle(FileHandle, ScriptPath);\r
 \r
         //\r
         // now close the file\r
@@ -2822,7 +2824,7 @@ RunScriptFile (
         ShellCloseFile(&FileHandle);\r
       }\r
     } else {\r
-      Status = RunScriptFileHandle(Handle, ScriptPath, ExitStatus);\r
+      Status = RunScriptFileHandle(Handle, ScriptPath);\r
     }\r
   }\r
 \r