Revision 9192
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sh | ||
---|---|---|
241 | 241 |
|
242 | 242 |
## external commands |
243 | 243 |
|
244 |
function command() # usage: [stderr_is_errors=1] command extern_cmd... |
|
244 |
function command() |
|
245 |
# usage: [stdout2stderr=1] [stderr_is_errors=1] [limit_stderr=1] command \ |
|
246 |
# extern_cmd... |
|
245 | 247 |
# to view only explicitly-displayed errors: explicit_errors_only=1 script... |
246 | 248 |
{ |
247 | 249 |
test "$cmd_echoed" || echo_run_prep |
248 |
set -- -- "$@" # prepend -- so command name not treated as `command` option |
|
249 |
set -- builtin command "$@" |
|
250 |
if test "$stderr_is_errors"; then "$@" 2>&22 # ensure errors are visible |
|
251 |
else "$@"; fi |
|
250 |
( |
|
251 |
if test "$limit_stderr"; then limit_stderr; fi |
|
252 |
if test "$stderr_is_errors"; then exec 2>&22; fi # ensure errors visible |
|
253 |
builtin command -- "$@" # -- so cmd name not treated as `command` option |
|
254 |
) || return |
|
252 | 255 |
} |
253 | 256 |
|
254 | 257 |
# auto-echo common external commands |
... | ... | |
285 | 288 |
fi |
286 | 289 |
|
287 | 290 |
|
288 |
### external command verbose output |
|
289 |
|
|
290 |
limit_stderr_cmd() # usage: [stdout2stderr=1] limit_stderr_cmd cmd... |
|
291 |
{ |
|
292 |
case "$1" in command) echo_run_prep; local cmd_echoed=1;; esac |
|
293 |
(limit_stderr; "$@") || return |
|
294 |
} |
|
295 |
alias limit_stderr_cmd='"limit_stderr_cmd" ' #last space alias-expands next word |
|
296 |
alias limit_stdout_cmd='stdout2stderr=1 limit_stderr_cmd ' |
|
297 |
# last space alias-expands next word |
|
298 |
|
|
299 |
|
|
300 | 291 |
### external command input/output |
301 | 292 |
|
302 | 293 |
# usage: cmd1 | { pipe_delay; cmd2; } |
Also available in: Unified diff
lib/sh/util.sh: merged limit_stderr_cmd/limit_stdout_cmd into command(), using flag vars to control what limiting actions it needs to perform. in command invocations, this involves setting the appropriate flag vars instead of using a limit_std*_cmd alias.