diff -ur pdksh-5.2.14.orig/history.c pdksh-5.2.14/history.c --- pdksh-5.2.14.orig/history.c Mon May 10 15:13:06 1999 +++ pdksh-5.2.14/history.c Mon Aug 7 00:06:33 2000 @@ -610,7 +610,18 @@ { register char **hp = histptr; char *cp; + int l; + /* don't save if command is the same as last one */ + if (hp >= history && *hp != NULL) { + l = strlen(cmd); + if (strcmp(*hp, cmd) == 0) + return; + else if ((cmd[l-1] == '\n') + && (strlen(*hp) == l-1) + && strncmp(*hp, cmd, l - 1) == 0) + return; + } if (++hp >= history + histsize) { /* remove oldest command */ afree((void*)history[0], APERM); memmove(history, history + 1, @@ -700,9 +711,13 @@ nread = fread(hline, 1, LINE, fh); if (nread <= 0) break; - hline[nread] = '\0'; + hline[nread] = '\n'; } - end = strchr(hline + pos, 0); /* will always succeed */ + end = strchr(hline + pos, '\n'); /* will always succeed - 0, but not \n!!! */ + if(end != NULL) /* in case sth put \0 in .history...) */ + *end = '\0'; + else + end = strchr(hline + pos, '\0'); /* THIS will always succeed */ if (contin) histappend(hline + pos, 0); else { @@ -742,7 +754,7 @@ if (hname && (fh = fopen(hname, "w"))) { for (i = 0; hp + i <= histptr && hp[i]; i++) - fprintf(fh, "%s%c", hp[i], '\0'); + fprintf(fh, "%s\n", hp[i]); fclose(fh); } }