diff --git a/psh/echo/echo.c b/psh/echo/echo.c index 8310cd15..ad54f60d 100644 --- a/psh/echo/echo.c +++ b/psh/echo/echo.c @@ -90,8 +90,8 @@ static int psh_echo(int argc, char **argv) } } - for (i = optind; i < argend; ++i) { - if (i != optind) { + for (i = 1; i < argend; ++i) { + if (i != 1) { fputc(' ', output); } diff --git a/psh/mem/mem.c b/psh/mem/mem.c index ff584416..0f241dee 100644 --- a/psh/mem/mem.c +++ b/psh/mem/mem.c @@ -319,7 +319,7 @@ static int psh_sharedMaps(void) static int psh_mem(int argc, char **argv) { - int c; + int c, ind; if (argc == 1) return psh_mem_summary() < 0 ? EXIT_FAILURE : EXIT_SUCCESS; @@ -343,8 +343,9 @@ static int psh_mem(int argc, char **argv) } } - if (optind < argc) { - fprintf(stderr, "mem: unknown argument: %s\n", argv[optind]); + if (optind <= argc) { + ind = (optind == argc) ? optind - 1 : optind; + fprintf(stderr, "mem: unknown argument: %s\n", argv[ind]); return EXIT_FAILURE; } diff --git a/psh/pshapp/pshapp.c b/psh/pshapp/pshapp.c index 786f0be8..5cb6adba 100644 --- a/psh/pshapp/pshapp.c +++ b/psh/pshapp/pshapp.c @@ -945,7 +945,7 @@ int psh_history(int argc, char **argv) } /* History command doesn't take any arguments */ - if (optind < argc) { + if (optind <= argc && !help && !clear) { psh_historyhelp(); return EXIT_FAILURE; }