diff options
| author | Stefan Farfeleder <stefanf@FreeBSD.org> | 2005-12-26 15:43:54 +0000 |
|---|---|---|
| committer | Stefan Farfeleder <stefanf@FreeBSD.org> | 2005-12-26 15:43:54 +0000 |
| commit | 78952251bd60b6e5f6bdb062821c3253952471ad (patch) | |
| tree | 0f0ac2c16130c4e733e8bf8e922d9ae459dafe42 /bin | |
| parent | c4978601e8ca66ad3422323e5fc225c71bae2b4b (diff) | |
Notes
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/builtins.def | 18 | ||||
| -rw-r--r-- | bin/sh/eval.c | 26 | ||||
| -rw-r--r-- | bin/sh/eval.h | 1 | ||||
| -rw-r--r-- | bin/sh/output.c | 4 | ||||
| -rw-r--r-- | bin/sh/sh.1 | 58 | ||||
| -rw-r--r-- | bin/sh/trap.c | 11 |
6 files changed, 79 insertions, 39 deletions
diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def index 7bfe5d529cf1..8159a38e21cd 100644 --- a/bin/sh/builtins.def +++ b/bin/sh/builtins.def @@ -47,12 +47,12 @@ # NOTE: bltincmd must come first! bltincmd builtin -commandcmd command -#alloccmd alloc +aliascmd alias bgcmd -j bg +bindcmd bind breakcmd break continue -#catfcmd catf cdcmd cd chdir +commandcmd command dotcmd . echocmd echo evalcmd eval @@ -62,15 +62,13 @@ expcmd exp let exportcmd export readonly #exprcmd expr falsecmd false -histcmd -h fc fgcmd -j fg getoptscmd getopts hashcmd hash +histcmd -h fc jobidcmd jobid jobscmd jobs -#linecmd line localcmd local -#nlechocmd nlecho #printfcmd printf pwdcmd pwd readcmd read @@ -78,16 +76,14 @@ returncmd return setcmd set setvarcmd setvar shiftcmd shift +testcmd test [ +timescmd times trapcmd trap truecmd : true typecmd type +ulimitcmd ulimit umaskcmd umask unaliascmd unalias unsetcmd unset waitcmd wait -#foocmd foo -aliascmd alias -ulimitcmd ulimit -testcmd test [ -bindcmd bind wordexpcmd wordexp diff --git a/bin/sh/eval.c b/bin/sh/eval.c index fecc4de6199d..031cab310bf0 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include <signal.h> #include <stdlib.h> #include <unistd.h> +#include <sys/resource.h> #include <sys/wait.h> /* For WIFSIGNALED(status) */ #include <errno.h> @@ -1078,3 +1079,28 @@ execcmd(int argc, char **argv) } return 0; } + + +int +timescmd(int argc __unused, char **argv __unused) +{ + struct rusage ru; + long shumins, shsmins, chumins, chsmins; + double shusecs, shssecs, chusecs, chssecs; + + if (getrusage(RUSAGE_SELF, &ru) < 0) + return 1; + shumins = ru.ru_utime.tv_sec / 60; + shusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.; + shsmins = ru.ru_stime.tv_sec / 60; + shssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.; + if (getrusage(RUSAGE_CHILDREN, &ru) < 0) + return 1; + chumins = ru.ru_utime.tv_sec / 60; + chusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.; + chsmins = ru.ru_stime.tv_sec / 60; + chssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.; + out1fmt("%ldm%.3fs %ldm%.3fs\n%ldm%.3fs %ldm%.3fs\n", shumins, + shusecs, shsmins, shssecs, chumins, chusecs, chsmins, chssecs); + return 0; +} diff --git a/bin/sh/eval.h b/bin/sh/eval.h index 2f8471ef1c99..01c914acf880 100644 --- a/bin/sh/eval.h +++ b/bin/sh/eval.h @@ -56,6 +56,7 @@ int returncmd(int, char **); int falsecmd(int, char **); int truecmd(int, char **); int execcmd(int, char **); +int timescmd(int, char **); int commandcmd(int, char **); /* in_function returns nonzero if we are currently evaluating a function */ diff --git a/bin/sh/output.c b/bin/sh/output.c index 3550cb7ecb7d..b59e11e0e870 100644 --- a/bin/sh/output.c +++ b/bin/sh/output.c @@ -134,6 +134,10 @@ outqstr(const char *p, struct output *file) { char ch; + if (p[0] == '\0') { + outstr("''", file); + return; + } if (p[strcspn(p, "|&;<>()$`\\\"'")] == '\0' && (!ifsset() || p[strcspn(p, ifsval())] == '\0')) { outstr(p, file); diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index 5e792d416905..6fa59ede50c2 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd October 29, 2005 +.Dd December 8, 2005 .Dt SH 1 .Os .Sh NAME @@ -209,7 +209,11 @@ option if it has been set). Exit immediately if any untested command fails in non-interactive mode. The exit status of a command is considered to be explicitly tested if the command is part of the list used to control -an if, elif, while, or until; if the command is the left +an +.Ic if , elif , while , +or +.Ic until ; +if the command is the left hand operand of an .Dq Li && or @@ -431,7 +435,7 @@ This use is discouraged. .Pp An alias name may be escaped in a command line, so that it is not replaced by its alias value, by using quoting characters within or -adjacent to the alias name. +adjacent to the alias name. This is most often done by prefixing an alias name with a backslash to execute a function, built-in, or normal program with the same name. @@ -893,7 +897,7 @@ and the syntax is: .Bd -ragged -offset indent .Ic local .Op Ar variable ... -.Op Ar - +.Op Fl .Ed .Pp The @@ -1478,7 +1482,7 @@ that is guaranteed to find all of the standard utilities. .Pp If the .Fl v -option is specified, +option is specified, .Ar utility is not executed but a description of its interpretation by the shell is printed. @@ -1497,24 +1501,17 @@ It prints where .Ar description is either -.Bl -item -offset indent -.It the path name to .Ar utility , -.It -.Ic a shell builtin , -.It -.Ic a shell function , -.It -.Ic a shell keyword +a shell builtin, +a shell function, +a shell keyword or -.It -.Ic an alias for Ar value . -.El -.It Ic echo Oo Fl e | n Oc Op Ar string -Print -.Ar string -to the standard output with a newline appended. +an alias for +. Ar value . +.It Ic echo Oo Fl e | n Oc Op Ar string ... +Print a space-separated list of the arguments to the standard output +and append a newline character. .Bl -tag -width indent .It Fl n Suppress the output of the trailing newline. @@ -1780,7 +1777,7 @@ option is specified, the PID of each job is also printed. If the .Fl s option is specified, only the PIDs of the jobs are printed, one per line. -.It Ic local Oo Ar variable ... Oc Op Ar - +.It Ic local Oo Ar variable ... Oc Op Fl See the .Sx Functions subsection. @@ -1954,7 +1951,13 @@ A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3, and so on, decreasing the value of $# by one. If there are zero positional parameters, shifting does not do anything. +.It Ic times +Print the amount of time spent executing the shell and its children. +The first output line shows the user and system times for the shell +itself, the second one contains the user and system times for the +children. .It Ic trap Oo Ar action Oc Ar signal ... +.It Ic trap Fl l Cause the shell to parse and execute .Ar action when any specified @@ -1966,14 +1969,25 @@ In addition, the pseudo-signal may be used to specify an action that is performed when the shell terminates. The .Ar action -may be null or omitted; +may be an empty string or a dash +.Pq Ar - ; the former causes the specified signal to be ignored and the latter causes the default action to be taken. +Omitting the +.Ar action +is another way to request the default action, for compatibility reasons this +usage is not recommended though. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The .Ic trap command has no effect on signals that were ignored on entry to the shell. +.Pp +Option +.Fl l +causes the +.Ic trap +command to display a list of valid signal names. .It Ic type Op Ar name ... Interpret each .Ar name diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 5f12379e950b..71a14bacfcf1 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -153,15 +153,14 @@ trapcmd(int argc, char **argv) if (argc <= 1) { for (signo = 0 ; signo < sys_nsig ; signo++) { if (signo < NSIG && trap[signo] != NULL) { + out1str("trap -- "); + out1qstr(trap[signo]); if (signo == 0) { - out1fmt("trap -- '%s' %s\n", - trap[signo], "exit"); + out1str(" exit\n"); } else if (sys_signame[signo]) { - out1fmt("trap -- '%s' %s\n", - trap[signo], sys_signame[signo]); + out1fmt(" %s\n", sys_signame[signo]); } else { - out1fmt("trap -- '%s' %d\n", - trap[signo], signo); + out1fmt(" %d\n", signo); } } } |
