Revision 9473
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sh | ||
---|---|---|
539 | 539 |
disable_logging() { set_fds "$log_fd>/dev/null"; } |
540 | 540 |
|
541 | 541 |
function command() |
542 |
# usage: [cmd_log_fd=|1|2|#] [verbosity_min=] command extern_cmd... |
|
542 |
# usage: [cmd_log_fd=|1|2|#] [redirs=...] [verbosity_min=] command extern_cmd...
|
|
543 | 543 |
# to view only explicitly-displayed errors: explicit_errors_only=1 script... |
544 | 544 |
{ |
545 |
kw_params cmd_log_fd verbosity_min |
|
545 |
kw_params cmd_log_fd redirs verbosity_min
|
|
546 | 546 |
# if no cmd_log_fd, limit log_fd in case command uses util.sh |
547 | 547 |
local cmd_log_fd="${cmd_log_fd-$log_fd}" |
548 |
local redirs=("${redirs[@]}") |
|
548 | 549 |
|
549 | 550 |
# determine redirections now so they can be logged along with the command |
550 |
local _redirs=() # prepend _ to avoid collisions with command's kw params |
|
551 | 551 |
# the following redirections must happen in exactly this order |
552 | 552 |
if test "$cmd_log_fd"; then |
553 | 553 |
if can_log; then |
554 | 554 |
if test "$cmd_log_fd" != "$log_fd"; then |
555 |
_redirs+=("$cmd_log_fd>&$log_fd")
|
|
555 |
redirs+=("$cmd_log_fd>&$log_fd") |
|
556 | 556 |
fi # else no redir needed |
557 |
else _redirs+=("$cmd_log_fd>/dev/null");
|
|
557 |
else redirs+=("$cmd_log_fd>/dev/null"); |
|
558 | 558 |
fi |
559 | 559 |
fi |
560 | 560 |
|
561 |
cmd2rel_path; echo_cmd "$@" "${_redirs[@]}"
|
|
561 |
cmd2rel_path; echo_cmd "$@" "${redirs[@]}" |
|
562 | 562 |
|
563 | 563 |
# add after echoing command so it isn't echoed at the end of every command |
564 | 564 |
if test "$cmd_log_fd" != 2; then # fd 2 not used for logging |
565 |
_redirs+=("2>&$err_fd") # assume fd 2 used for errors
|
|
565 |
redirs+=("2>&$err_fd") # assume fd 2 used for errors |
|
566 | 566 |
fi |
567 | 567 |
|
568 | 568 |
( |
569 | 569 |
if can_log; then indent; fi |
570 |
log++ set_fds "${_redirs[@]}"
|
|
570 |
log++ set_fds "${redirs[@]}" |
|
571 | 571 |
|
572 | 572 |
if test "$verbosity_min"; then verbosity_min "$verbosity_min"; fi |
573 | 573 |
|
Also available in: Unified diff
lib/sh/util.sh: command(): support custom redirections, which will be echoed along with the command