diff -r 9c35ada030a5 -r e8a11323f1ef builtins.c --- a/builtins.c Mon Jul 26 23:35:51 2010 -0400 +++ b/builtins.c Mon Jul 26 23:44:23 2010 -0400 @@ -26,6 +26,8 @@ #include "timestamp.h" #include "md5.h" #include +# include +# include /* @@ -2113,6 +2115,14 @@ #endif +static char * rtrim(char *s) +{ + char *p = s; + while(*p) ++p; + for(--p; p >= s && isspace(*p); *p-- = 0); + return s; +} + LIST * builtin_shell( PARSE * parse, FRAME * frame ) { LIST * command = lol_get( frame->args, 0 ); @@ -2124,6 +2134,7 @@ int exit_status = -1; int exit_status_opt = 0; int no_output_opt = 0; + int strip_eol_opt = 0; /* Process the variable args options. */ { @@ -2139,6 +2150,10 @@ { no_output_opt = 1; } + else if ( strcmp("strip-eol", arg->string) == 0 ) + { + strip_eol_opt = 1; + } arg = lol_get( frame->args, ++a ); } } @@ -2160,6 +2175,8 @@ buffer[ret] = 0; if ( !no_output_opt ) { + if ( strip_eol_opt ) + rtrim(buffer); string_append( &s, buffer ); } } @@ -2173,6 +2190,10 @@ /* The command exit result next. */ if ( exit_status_opt ) { + if ( WIFEXITED(exit_status) ) + exit_status = WEXITSTATUS(exit_status); + else + exit_status = -1; sprintf( buffer, "%d", exit_status ); result = list_new( result, newstr( buffer ) ); }