Project

General

Profile

« Previous | Next » 

Revision 10920

bugfix: lib/sh/util.sh: set_fds(): need to check if redirect is empty before escaping it with `printf %q`, which may add surrounding quotes to an empty string

View differences:

lib/sh/util.sh
628 628
	# add #<>&- before every #<>&# reopen to fix strange bash bug
629 629
	local redirs=() i
630 630
	for i in "$@"; do
631
		local redir_prefix="$(match_prefix '*[<>]' "$i")"
632
		local dest="$(        rm_prefix    '*[<>]' "$i")"
633
		if ! starts_with '&' "$dest"; then # escape dest
634
			i="$redir_prefix$(printf %q "$dest")"
635
		fi
636
		if test "$redir_prefix"; then redirs+=("$redir_prefix&-"); fi
637 631
		# remove empty redirects resulting from using `redirs= cmd...` to clear
638 632
		# the redirs and then using $redirs as an array
639
		if test "$i"; then redirs+=("$i"); fi
633
		if test "$i"; then
634
			local redir_prefix="$(match_prefix '*[<>]' "$i")"
635
			local dest="$(        rm_prefix    '*[<>]' "$i")"
636
			if ! starts_with '&' "$dest"; then # escape dest
637
				i="$redir_prefix$(printf %q "$dest")"
638
			fi
639
			if test "$redir_prefix"; then redirs+=("$redir_prefix&-"); fi
640
			redirs+=("$i")
641
		fi
640 642
	done
641 643
	set -- "${redirs[@]}"
642 644
	

Also available in: Unified diff