[Devel] Using Here-doc instead of echo "..."

Kir Kolyshkin kir at parallels.com
Sun Apr 28 21:32:19 PDT 2013


On 04/28/2013 08:31 PM, Igor Podlesny wrote:
> -- Here-doc is generally more readable/writeable way to implement
> "patterns" in SHELL.

I can't apply this because it depends on the previous patch which you 
have to fix,
so please resend both.

Generally, it makes sense to patch things in an order opposite from the 
one you did;
first you do some trivial stuff, such as formatting, cleanups etc, then 
go on with less
trivial. That way your trivial stuff will always be merged and you don't 
have to redo it.
Hope that makes sense.

> ---
>   etc/dists/scripts/debian-add_ip.sh |    9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/etc/dists/scripts/debian-add_ip.sh b/etc/dists/scripts/debian-add_ip.sh
> index 80e8e73..d38e65f 100755
> --- a/etc/dists/scripts/debian-add_ip.sh
> +++ b/etc/dists/scripts/debian-add_ip.sh
> @@ -47,7 +47,8 @@ setup_network()
>   				"${CFGFILE}-$(date --rfc-3339=seconds).bak"
>   		}
>   
> -	echo "# This configuration file is auto-generated.
> +	cat > "$CFGFILE" <<__ETC_NET_INT__
> +# This configuration file is auto-generated.
>   #
>   # $DONT_EDIT, your changes will be lost.
>   # Please create/edit $CFGFILE.head and
> @@ -57,7 +58,7 @@ setup_network()
>   # NOTE: it is NOT guaranteed that the contents of $CFGFILE.tail
>   # will be at the very end of this file.
>   #
> -" > ${CFGFILE}
> +__ETC_NET_INT__
>   
>   	if [ -f ${CFGFILE}.head ]; then
>   		cat ${CFGFILE}.head >> ${CFGFILE}
> @@ -84,7 +85,7 @@ iface ${LOOPBACK} inet loopback" >> ${CFGFILE}
>   
>   	if [ -n "${IP_ADDR}" ]; then
>   		# Set up venet0
> -		echo "
> +		cat >> "$CFGFILE" <<__VENET__
>   # Auto generated ${VENET_DEV} interface
>   auto ${VENET_DEV}
>   iface ${VENET_DEV} inet manual
> @@ -93,7 +94,7 @@ iface ${VENET_DEV} inet manual
>   	up route add default dev ${VENET_DEV}
>   	down route del default dev ${VENET_DEV}
>   	down ifconfig ${VENET_DEV} down
> -" >> ${CFGFILE}
> +__VENET__
>   
>   		if [ "${IPV6}" = "yes" ]; then
>   			echo "




More information about the Devel mailing list