long repeat;
     int dbnum;
     int interactive;
+    int shutdown;
     int monitor_mode;
     int pubsub_mode;
     int raw_output;
 static int cliReadReply(int fd) {
     char type;
 
-    if (anetRead(fd,&type,1) <= 0) exit(1);
+    if (anetRead(fd,&type,1) <= 0) {
+        if (config.shutdown) return 0;
+        exit(1);
+    }
     switch(type) {
     case '-':
         printf("(error) ");
 
 static int cliSendCommand(int argc, char **argv, int repeat) {
     struct redisCommand *rc = lookupCommand(argv[0]);
-    int shutdown = 0;
     int fd, j, retval = 0;
     sds cmd;
 
             return 1;
     }
 
-    if (!strcasecmp(rc->name,"shutdown")) shutdown = 1;
+    if (!strcasecmp(rc->name,"shutdown")) config.shutdown = 1;
     if (!strcasecmp(rc->name,"monitor")) config.monitor_mode = 1;
     if (!strcasecmp(rc->name,"subscribe") ||
         !strcasecmp(rc->name,"psubscribe")) config.pubsub_mode = 1;
         }
 
         retval = cliReadReply(fd);
+
         if (retval) {
-            return shutdown ? 0 : retval;
+            return retval;
         }
     }
     return 0;
     config.hostport = 6379;
     config.repeat = 1;
     config.dbnum = 0;
+    config.shutdown = 0;
     config.interactive = 0;
     config.monitor_mode = 0;
     config.pubsub_mode = 0;