Revision 9257
Added by Aaron Marcuse-Kubitza about 11 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: dest=fd expr='[<>]src' [noclobber=1] set_fd
|
|
397 |
set_fd() # usage: expr='dest[<>]src' [noclobber=1] set_fd
|
|
398 | 398 |
{ |
399 |
echo_func; kw_params dest expr |
|
400 |
: "${dest:?}" "${expr:?}" |
|
399 |
echo_func; kw_params expr |
|
400 |
: "${expr:?}" |
|
401 |
local dest="${expr%%[<>]*}" |
|
401 | 402 |
test ! "$noclobber" || require_fd_not_exists "$dest" || return 0 |
402 |
echo_eval exec "$dest$expr"
|
|
403 |
echo_eval exec "$expr" |
|
403 | 404 |
} |
404 | 405 |
|
405 |
shadow_fd() { noclobber=1 set_fd; } # usage: dest=fd expr='[<>]src' shadow_fd
|
|
406 |
shadow_fd() { noclobber=1 set_fd; } # usage: expr='dest[<>]src' shadow_fd
|
|
406 | 407 |
|
407 | 408 |
# convention: use fd 10/11/12 for command-specific alternate stdin/stdout/stderr |
408 | 409 |
|
... | ... | |
412 | 413 |
{ |
413 | 414 |
log++; echo_func; log++ |
414 | 415 |
# ignore errors if a source fd isn't open |
415 |
dest=20 expr='<&0' shadow_fd || true
|
|
416 |
dest=21 expr='>&1' shadow_fd || true
|
|
417 |
dest=22 expr='>&2' shadow_fd || true
|
|
416 |
expr='20<&0' shadow_fd || true
|
|
417 |
expr='21>&1' shadow_fd || true
|
|
418 |
expr='22>&2' shadow_fd || true
|
|
418 | 419 |
} |
419 | 420 |
set_global_fds |
420 | 421 |
err_fd=22 # global stderr |
Also available in: Unified diff
lib/sh/util.sh: set_fd()/shadow_fd(): take just a redirect expr containing the entire dest[<>]src expr, and parse the dest out from it