[LEDE-DEV] [patch master 11/15] Consider using { cmd1; cmd2; } >> file instead of individual redirects

Oswald Buddenhagen oswald.buddenhagen at gmx.de
Sat Oct 1 02:19:54 PDT 2016


On Fri, Sep 30, 2016 at 10:02:25PM +0200, Jan-Tarek Butt wrote:
> diff --git a/scripts/config/lxdialog/check-lxdialog.sh b/scripts/config/lxdialog/check-lxdialog.sh
> -	    echo " *** Unable to find the ncurses libraries or the"       1>&2
> -	    echo " *** required header files."                            1>&2
> -	    echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
> -	    echo " *** "                                                  1>&2
> -	    echo " *** Install ncurses (ncurses-devel) and try again."    1>&2
> -	    echo " *** "                                                  1>&2
> -	    exit 1
> +		{
> +			echo " *** Unable to find the ncurses libraries or the"
> +			echo " *** required header files."
> +			echo " *** 'make menuconfig' requires the ncurses libraries."
> +			echo " ***"
> +			echo " *** Install ncurses (ncurses-devel) and try again."
> +			echo " ***"
> +		} 1>&2
> +		exit 1
>  	fi
>  }

i would suggest using a 'here document' instead:

cat >&2 <<EOF
 *** Unable ...
EOF

> diff --git a/scripts/ext-toolchain.sh b/scripts/ext-toolchain.sh
>  	local bin="$2"
>  
>  	echo    '#!/bin/sh'                                                > "$out"
> -	echo    'for arg in "$@"; do'                                     >> "$out"
> -	echo    ' case "$arg" in -l*|-L*|-shared|-static)'                >> "$out"
> -	echo -n '  exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'           >> "$out"
> -	echo -n '-idirafter "$STAGING_DIR/usr/include" '                  >> "$out"
> -	echo -n '-L "$STAGING_DIR/usr/lib" '                              >> "$out"
> -	echo    '-Wl,-rpath-link,"$STAGING_DIR/usr/lib"} "$@" ;;'         >> "$out"
> -	echo    ' esac'                                                   >> "$out"
> -	echo    'done'                                                    >> "$out"
> -	echo -n 'exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'             >> "$out"
> -	echo    '-idirafter "$STAGING_DIR/usr/include"} "$@"'             >> "$out"
> +	{
> +		echo    'for arg in "$@"; do'
> +		echo    ' case "$arg" in -l*|-L*|-shared|-static)'
> +		echo -n '  exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'
> +		echo -n '-idirafter "$STAGING_DIR/usr/include" '
> +		echo -n '-L "$STAGING_DIR/usr/lib" '
> +		echo    '-Wl,-rpath-link,"$STAGING_DIR/usr/lib"} "$@" ;;'
> +		echo    ' esac'
> +		echo    'done'
> +		echo -n 'exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'
> +		echo    '-idirafter "$STAGING_DIR/usr/include"} "$@"'
> +	} >> "$out"
>  
here as well, but note that you'd need to escape some of the dollars
(yeah, this is in direct contradiction to the other response).

note that you can't use the bash extension to prevent expansion:

  cat > "$out" <<'EOF'

because some of the variables actually *are* expanded.



More information about the Lede-dev mailing list