diff --git a/NEWS b/NEWS index 52d44e4d5..079109f00 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0 Any uppercase BUG_* names are modernish shell bug IDs. +2022-06-12: + +- The POSIX mode now disables zero-padding of seconds in 'time'/'times' output. + 2022-06-09: - The POSIX mode has been amended to use a UNIX pipe(2) instead of a diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c index e36ce55a5..a22ef3963 100644 --- a/src/cmd/ksh93/bltins/misc.c +++ b/src/cmd/ksh93/bltins/misc.c @@ -519,7 +519,7 @@ static void print_times(struct timeval utime, struct timeval stime) int st_min = stime.tv_sec / 60; int st_sec = stime.tv_sec % 60; int st_ms = stime.tv_usec / 1000; - sfprintf(sfstdout, "%dm%02d%c%03ds %dm%02d%c%03ds\n", + sfprintf(sfstdout, sh_isoption(SH_POSIX) ? "%dm%d%c%03ds %dm%d%c%03ds\n" : "%dm%02d%c%03ds %dm%02d%c%03ds\n", ut_min, ut_sec, sh.radixpoint, ut_ms, st_min, st_sec, sh.radixpoint, st_ms); } #if _lib_getrusage diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index e2548e5d9..1896808d6 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -23,7 +23,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2022-06-09" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2022-06-12" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 361308e49..ee7df4b57 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -2296,6 +2296,9 @@ hours if greater than zero, minutes, and seconds of the form \fIHH\fPh\fIMM\fPm\fISS\fP.\fIFF\fPs. The value of \fIp\fP determines whether or not the fraction is included. +Seconds are zero-padded unless the +.B posix +shell option is on. .IP All other characters are output without change and a trailing newline is added. @@ -7747,6 +7750,12 @@ enables the recognition of a leading zero as introducing an octal number in all arithmetic evaluation contexts, except in the \fBlet\fR built-in while \fBletoctal\fR is off; .IP \[bu] +disables zero-padding of seconds in the output of the +.B time +and +.B times +built-ins; +.IP \[bu] stops the \fB.\fR command (but not \fBsource\fR) from looking up functions defined with the \fBfunction\fR syntax; .IP \[bu] @@ -7987,6 +7996,9 @@ or Displays the accumulated user and system CPU times, one line with the times used by the shell and another with those used by all of the shell's child processes. No options are supported. +Seconds are zero-padded unless the +.B posix +shell option is on. .TP \(dg \f3trap\fP \*(OK \f3\-p\fP \*(CK \*(OK \f2action\^\fP \*(CK \*(OK \f2sig\^\fP \*(CK .\|.\|. The diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index f313635f4..7dbea860c 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -239,9 +239,9 @@ static void l_time(Sfio_t *outfile,register clock_t t,int precision) if(hr) sfprintf(outfile,"%dh",hr); if(precision) - sfprintf(outfile,"%dm%02d%c%0*ds",min,sec,sh.radixpoint,precision,frac); + sfprintf(outfile, sh_isoption(SH_POSIX) ? "%dm%d%c%0*ds" : "%dm%02d%c%0*ds", min, sec, sh.radixpoint, precision, frac); else - sfprintf(outfile,"%dm%02ds",min,sec); + sfprintf(outfile, sh_isoption(SH_POSIX) ? "%dm%ds" : "%dm%02ds", min, sec); } #define TM_REAL_IDX 0 @@ -2401,11 +2401,9 @@ int sh_exec(register const Shnode_t *t, int flags) if(t->par.partre) { - Namval_t *np = nv_open("TIMEFORMAT",sh.var_tree,NV_NOADD); - if(np) + Namval_t *np; + if(np = nv_open("TIMEFORMAT",sh.var_tree,NV_NOADD)) format = nv_getval(np); - if(!format) - format = e_timeformat; } else format = strchr(format+1,'\n')+1; diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 5fd7f2044..e3718205e 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -746,11 +746,11 @@ then fi # ====== -# 'times' builtin +# 'time' keyword and 'times' builtin -expect=$'0m00.0[0-9][0-9]s 0m00.0[0-9][0-9]s\n0m00.000s 0m00.000s' -actual=$("$SHELL" -c times) -[[ $actual == $expect ]] || err_exit "times output: expected $(printf %q "$expect"), got $(printf %q "$actual")" +exp=$'^user\t0m00.[0-9]{2}s\nsys\t0m00.[0-9]{2}s\n0m00.[0-9]{3}s 0m00.[0-9]{3}s\n0m00.000s 0m00.000s$' +got=$("$SHELL" -c '{ time; } 2>&1; times') +[[ $got =~ $exp ]] || err_exit "times output: expected match of $(printf %q "$exp"), got $(printf %q "$got")" expect=$'*: times: too many operands' actual=$(set +x; eval 'times Extra Args' 2>&1) diff --git a/src/cmd/ksh93/tests/posix.sh b/src/cmd/ksh93/tests/posix.sh index 4330c2898..760096d7a 100644 --- a/src/cmd/ksh93/tests/posix.sh +++ b/src/cmd/ksh93/tests/posix.sh @@ -197,6 +197,11 @@ let "017 == 15" || err_exit "leading octal zero not recognised in 'let' in --pos (set --noposix --letoctal; let "017 == 15") || err_exit "leading octal zero not recognised in --noposix --letoctal (1)" (set --noposix; set --letoctal; let "017 == 15") || err_exit "leading octal zero not recognised in --noposix --letoctal (2)" +# disables zero-padding of seconds in the output of the time and times built-ins; +exp=$'^user\t0m0.[0-9]{2}s\nsys\t0m0.[0-9]{2}s\n0m0.[0-9]{3}s 0m0.[0-9]{3}s\n0m0.000s 0m0.000s$' +got=$("$SHELL" --posix -c '{ time; } 2>&1; times') +[[ $got =~ $exp ]] || err_exit "POSIX time/times output: expected match of $(printf %q "$exp"), got $(printf %q "$got")" + # stops the . command (but not source) from looking up functions defined with the function syntax; echo 'echo SCRIPT' >scrunction function scrunction { echo FUNCTION; }