diff --git a/src/error.cpp b/src/error.cpp
index 5c24d94832d56a7ecf3d7ca040bc8b46572b88ea..0969507fc977b854aceae485a24e0fa9d4667d16 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -17,6 +17,7 @@
 #include "error.h"
 #include "universe.h"
 #include "output.h"
+#include "input.h"
 
 using namespace LAMMPS_NS;
 
@@ -107,11 +108,18 @@ void Error::all(const char *file, int line, const char *str)
   MPI_Barrier(world);
 
   int me;
+  const char *lastcmd = (const char*)"(unknown)";
+
   MPI_Comm_rank(world,&me);
 
   if (me == 0) {
-    if (screen) fprintf(screen,"ERROR: %s (%s:%d)\n",str,file,line);
-    if (logfile) fprintf(logfile,"ERROR: %s (%s:%d)\n",str,file,line);
+    if (input && input->line) lastcmd = input->line;
+    if (screen) fprintf(screen,"ERROR: %s (%s:%d)\n"
+		        "Last command: %s\n",
+                        str,file,line,lastcmd);
+    if (logfile) fprintf(logfile,"ERROR: %s (%s:%d)\n"
+		         "Last command: %s\n",
+                         str,file,line,lastcmd);
   }
 
 #ifdef LAMMPS_EXCEPTIONS
diff --git a/src/input.cpp b/src/input.cpp
index 258b4d7dd0ed35427e61a883c04278ad89ace8b9..76aba3d87e9201b7c1631c61297c0e51ba63f0fd 100644
--- a/src/input.cpp
+++ b/src/input.cpp
@@ -350,15 +350,15 @@ void Input::parse()
     }
     if (quoteflag == 0) {
       if (strstr(ptr,"\"\"\"") == ptr) {
-	quoteflag = 3;
-	ptr += 2;
+        quoteflag = 3;
+        ptr += 2;
       }
       else if (*ptr == '"') quoteflag = 2;
       else if (*ptr == '\'') quoteflag = 1;
     } else {
       if (quoteflag == 3 && strstr(ptr,"\"\"\"") == ptr) {
-	quoteflag = 0;
-	ptr += 2;
+        quoteflag = 0;
+        ptr += 2;
       }
       else if (quoteflag == 2 && *ptr == '"') quoteflag = 0;
       else if (quoteflag == 1 && *ptr == '\'') quoteflag = 0;
diff --git a/src/input.h b/src/input.h
index 7f9cefe064880fd8610f5e1c1a573d62f78a4228..9165ad9813b841bf379a4705f7a9fb5b6ce7cc41 100644
--- a/src/input.h
+++ b/src/input.h
@@ -23,6 +23,7 @@ namespace LAMMPS_NS {
 
 class Input : protected Pointers {
   friend class Info;
+  friend class Error;
  public:
   int narg;                    // # of command args
   char **arg;                  // parsed args for command