Revision 9258
Added by Aaron Marcuse-Kubitza almost 12 years ago
lib/sh/util.sh | ||
---|---|---|
394 | 394 |
require_fd_not_exists() # usage: require_fd_not_exists fd || return 0 |
395 | 395 |
{ ! fd_exists "$1" || type=info die "fd $1 already exists, skipping"; } |
396 | 396 |
|
397 |
set_fd() # usage: expr='dest[<>]src' [noclobber=1] set_fd
|
|
397 |
set_fd() # usage: [noclobber=1] set_fd 'dest[<>]src'
|
|
398 | 398 |
{ |
399 |
echo_func; kw_params expr |
|
400 |
: "${expr:?}" |
|
401 |
local dest="${expr%%[<>]*}" |
|
399 |
echo_func |
|
400 |
local dest="${1%%[<>]*}" |
|
402 | 401 |
test ! "$noclobber" || require_fd_not_exists "$dest" || return 0 |
403 |
echo_eval exec "$expr"
|
|
402 |
echo_eval exec "$1"
|
|
404 | 403 |
} |
405 | 404 |
|
406 |
shadow_fd() { noclobber=1 set_fd; } # usage: expr='dest[<>]src' shadow_fd
|
|
405 |
shadow_fd() { noclobber=1 set_fd "$@"; } # usage: shadow_fd 'dest[<>]src'
|
|
407 | 406 |
|
408 | 407 |
# convention: use fd 10/11/12 for command-specific alternate stdin/stdout/stderr |
409 | 408 |
|
... | ... | |
413 | 412 |
{ |
414 | 413 |
log++; echo_func; log++ |
415 | 414 |
# ignore errors if a source fd isn't open |
416 |
expr='20<&0' shadow_fd || true
|
|
417 |
expr='21>&1' shadow_fd || true
|
|
418 |
expr='22>&2' shadow_fd || true
|
|
415 |
shadow_fd '20<&0' || true
|
|
416 |
shadow_fd '21>&1' || true
|
|
417 |
shadow_fd '22>&2' || true
|
|
419 | 418 |
} |
420 | 419 |
set_global_fds |
421 | 420 |
err_fd=22 # global stderr |
Also available in: Unified diff
lib/sh/util.sh: set_fd()/shadow_fd(): take the redirect expr as an arg instead of a kw_param because it's the only param