Project

General

Profile

« Previous | Next » 

Revision 9125

lib/sh/util.sh: added streams functions fd_exists, set_fd, shadow_fd, and helpers

View differences:

lib/sh/util.sh
299 299
if self_being_included; then
300 300

  
301 301

  
302
#### streams
303

  
304
fd_exists () { (: <&"$1") 2>/dev/null; }
305

  
306
require_fd_not_exists() # usage: require_fd_not_exists fd || return 0
307
{ ! fd_exists "$1" || type=info die "fd $1 already exists, skipping"; }
308

  
309
set_fd () # usage: dest=fd dir='[<>]' src=fd [noclobber=1] set_fd
310
{
311
	inc_log_level; echo_func
312
	: "${dest:?}" "${dir:?}" "${src:?}"
313
	test ! "$noclobber" || require_fd_not_exists "$dest" || return 0
314
	echo_eval exec "$dest$dir&$src"
315
}
316

  
317
shadow_fd () # usage: prefix=# src=fd dir='[<>]' shadow_fd
318
{
319
	echo_minor_func
320
	: "${prefix:?}" "${src:?}" "${dir:?}"
321
	dest="$prefix$src" noclobber=1 set_fd
322
}
323

  
324

  
302 325
#### vars
303 326

  
304 327
set_var() { eval "$1"'="$2"'; }

Also available in: Unified diff