Replace "echo -e" with "printf" to have the same behavior in dash or bash
authorAndrei Gherzan <andrei@gherzan.ro>
Thu, 20 Sep 2012 09:56:59 +0000 (12:56 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 20 Sep 2012 12:33:50 +0000 (13:33 +0100)
oe-core removed the prerequisite to have sh as bash. POSIX doesn't define
any options and furthermore allows 'echo -e' to be the default behavior.
This means that in dash 'echo -e' will actually print '-e' and interpret
backslashes by default. We use instead 'printf' builtin command with or
without '\n' to simulate 'echo -e' or 'echo -n'.
'printf' needs format while 'echo' can be used without any arguments. So
'echo >' was replaced by 'printf "" >'.
'echo' without '-n' flag adds a new line by default so to keep the same
behavior of two new lines while using 'echo "\n"', 'printf "\n\n"' is
used.

[YOCTO #3138]

(From OE-Core rev: a19880ad10ccb5d7d909dcf9de5c3dc58a0ebcd3)

Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/buildhistory.bbclass
meta/classes/cml1.bbclass
meta/classes/license.bbclass
meta/classes/package_deb.bbclass
meta/classes/package_ipk.bbclass
meta/classes/package_rpm.bbclass
meta/classes/populate_sdk_base.bbclass
meta/recipes-core/base-files/base-files_3.0.14.bb
meta/recipes-extended/libzypp/libzypp_git.bb
meta/recipes-extended/lsb/lsb_4.1.bb
scripts/contrib/ddimage

index e121088..49f2ea5 100644 (file)
@@ -293,13 +293,13 @@ buildhistory_get_image_installed() {
        # Change delimiter from pipe to -> and set style for recommend lines
        sed -i -e 's:|: -> :' -e 's:\[REC\]:[style=dotted]:' -e 's:$:;:' ${BUILDHISTORY_DIR_IMAGE}/depends.tmp
        # Add header, sorted and de-duped contents and footer and then delete the temp file
-       echo -e "digraph depends {\n    node [shape=plaintext]" > ${BUILDHISTORY_DIR_IMAGE}/depends.dot
+       printf "digraph depends {\n    node [shape=plaintext]\n" > ${BUILDHISTORY_DIR_IMAGE}/depends.dot
        cat ${BUILDHISTORY_DIR_IMAGE}/depends.tmp | sort | uniq >> ${BUILDHISTORY_DIR_IMAGE}/depends.dot
        echo "}" >>  ${BUILDHISTORY_DIR_IMAGE}/depends.dot
        rm ${BUILDHISTORY_DIR_IMAGE}/depends.tmp
 
        # Produce installed package sizes list
-       echo -n > ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp
+       printf "" > ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp
        cat $pkgcache | while read pkg pkgfile
        do
                if [ -f $pkgfile ] ; then
@@ -330,7 +330,7 @@ buildhistory_get_imageinfo() {
        ( cd ${IMAGE_ROOTFS} && find . -ls | awk '{ if ( $7 ~ /[0-9]/ ) printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, $7, $11, $12, $13 ; else printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, 0, $10, $11, $12 }' | sort -k5 > ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt )
 
        # Record some machine-readable meta-information about the image
-       echo -n > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
+       printf ""  > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
        cat >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt <<END
 ${@buildhistory_get_imagevars(d)}
 END
index 67f17ad..37ed792 100644 (file)
@@ -20,7 +20,7 @@ python do_menuconfig() {
         except OSError:
             mtime = 0
 
-        oe_terminal("${SHELL} -c \"make menuconfig; if [ $? -ne 0 ]; then echo 'Command failed.'; echo -n 'Press any key to continue... '; read r; fi\"", '${PN} Configuration', d)
+        oe_terminal("${SHELL} -c \"make menuconfig; if [ $? -ne 0 ]; then echo 'Command failed.'; printf 'Press any key to continue... '; read r; fi\"", '${PN} Configuration', d)
 
         # FIXME this check can be removed when the minimum bitbake version has been bumped
         if hasattr(bb.build, 'write_taint'):
index 29fe938..ffcaf93 100644 (file)
@@ -112,16 +112,16 @@ license_create_manifest() {
                echo "PACKAGE NAME:" ${pkg} >> ${LICENSE_MANIFEST}
                echo "PACKAGE VERSION:" ${pkged_pv} >> ${LICENSE_MANIFEST}
                echo "RECIPE NAME:" ${pkged_pn} >> ${LICENSE_MANIFEST}
-               echo -n "LICENSE:" >> ${LICENSE_MANIFEST}
+               printf "LICENSE:" >> ${LICENSE_MANIFEST}
                for lic in ${pkged_lic}; do
                        # to reference a license file trim trailing + symbol
                        if [ -e "${LICENSE_DIRECTORY}/${pkged_pn}/generic_${lic%+}" ]; then
-                               echo -n " ${lic}" >> ${LICENSE_MANIFEST}
+                               printf " ${lic}" >> ${LICENSE_MANIFEST}
                        else
                                echo "WARNING: The license listed ${lic} was not in the licenses collected for ${pkged_pn}"
                        fi
                done
-               echo -e "\n" >> ${LICENSE_MANIFEST}
+               printf "\n\n" >> ${LICENSE_MANIFEST}
        done
 
        # Two options here:
index 48511df..3b42d3b 100644 (file)
@@ -192,7 +192,7 @@ deb_log_check() {
                if (echo "$lf_txt" | grep -v log_check | grep "$keyword_die") >/dev/null 2>&1
                then
                        echo "log_check: There were error messages in the logfile"
-                       echo -e "log_check: Matched keyword: [$keyword_die]\n"
+                       printf "log_check: Matched keyword: [$keyword_die]\n\n"
                        echo "$lf_txt" | grep -v log_check | grep -C 5 -i "$keyword_die"
                        echo ""
                        do_exit=1
index e94586e..efe299e 100644 (file)
@@ -181,7 +181,7 @@ ipk_log_check() {
                if (echo "$lf_txt" | grep -v log_check | grep "$keyword_die") >/dev/null 2>&1
                then
                        echo "log_check: There were error messages in the logfile"
-                       echo -e "log_check: Matched keyword: [$keyword_die]\n"
+                       printf "log_check: Matched keyword: [$keyword_die]\n\n"
                        echo "$lf_txt" | grep -v log_check | grep -C 5 -i "$keyword_die"
                        echo ""
                        do_exit=1
index 61f0117..64689d8 100644 (file)
@@ -110,7 +110,7 @@ rpm_log_check() {
                if (echo "$lf_txt" | grep -v log_check | grep "$keyword_die") >/dev/null 2>&1
                then
                        echo "log_check: There were error messages in the logfile"
-                       echo -e "log_check: Matched keyword: [$keyword_die]\n"
+                       printf "log_check: Matched keyword: [$keyword_die]\n\n"
                        echo "$lf_txt" | grep -v log_check | grep -C 5 -i "$keyword_die"
                        echo ""
                        do_exit=1
@@ -211,8 +211,8 @@ process_pkg_list_rpm() {
        pkgs="$@"
        local confbase=${INSTALL_CONFBASE_RPM}
 
-       echo -n > ${target_rootfs}/install/base_archs.pkglist
-       echo -n > ${target_rootfs}/install/ml_archs.pkglist
+       printf "" > ${target_rootfs}/install/base_archs.pkglist
+       printf "" > ${target_rootfs}/install/ml_archs.pkglist
 
        for pkg in $pkgs; do
                echo "Processing $pkg..."
index 1c151d7..2bff41f 100644 (file)
@@ -118,7 +118,7 @@ fakeroot create_shar() {
 
 DEFAULT_INSTALL_DIR="${SDKPATH}"
 
-echo -n "Enter target directory for Poky SDK (default: $DEFAULT_INSTALL_DIR): "
+printf "Enter target directory for Poky SDK (default: $DEFAULT_INSTALL_DIR): "
 read target_sdk_dir
 
 if [ "$target_sdk_dir" = "" ]; then
@@ -128,7 +128,7 @@ fi
 eval target_sdk_dir=$target_sdk_dir
 target_sdk_dir=$(readlink -m $target_sdk_dir)
 
-echo -n "You are about to install Poky SDK to \"$target_sdk_dir\". Proceed[Y/n]?"
+printf "You are about to install Poky SDK to \"$target_sdk_dir\". Proceed[Y/n]?"
 read answer
 
 if [ "$answer" = "" ]; then
@@ -148,11 +148,11 @@ fi
 
 payload_offset=$(($(grep -na -m1 "^MARKER:$" $(basename $0)|cut -d':' -f1) + 1))
 
-echo -n "Extracting SDK..."
+printf "Extracting SDK..."
 tail -n +$payload_offset $(basename $0) | tar xj --strip-components=4 -C $target_sdk_dir
 echo "done"
 
-echo -n "Setting it up..."
+printf "Setting it up..."
 # fix environment paths
 env_setup_script=$(find $target_sdk_dir -name "environment-setup-${REAL_MULTIMACH_TARGET_SYS}")
 sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script
index e80cff1..ba355ee 100644 (file)
@@ -117,11 +117,11 @@ do_install_basefilesissue () {
 
        install -m 644 ${WORKDIR}/issue*  ${D}${sysconfdir}  
         if [ -n "${DISTRO_NAME}" ]; then
-               echo -n "${DISTRO_NAME} " >> ${D}${sysconfdir}/issue
-               echo -n "${DISTRO_NAME} " >> ${D}${sysconfdir}/issue.net
+               printf "${DISTRO_NAME} " >> ${D}${sysconfdir}/issue
+               printf "${DISTRO_NAME} " >> ${D}${sysconfdir}/issue.net
                if [ -n "${DISTRO_VERSION}" ]; then
-                       echo -n "${DISTRO_VERSION} " >> ${D}${sysconfdir}/issue
-                       echo -n "${DISTRO_VERSION} " >> ${D}${sysconfdir}/issue.net
+                       printf "${DISTRO_VERSION} " >> ${D}${sysconfdir}/issue
+                       printf "${DISTRO_VERSION} " >> ${D}${sysconfdir}/issue.net
                fi
                echo "\n \l" >> ${D}${sysconfdir}/issue
                echo >> ${D}${sysconfdir}/issue
index 3a323e7..1729c78 100644 (file)
@@ -106,10 +106,10 @@ do_archgen () {
                                continue;;
                esac
                if [ "${AVOID_CONSTRUCTOR}" != "true" ]; then
-                 echo -n "  const Arch Arch_${each_arch} " | tr - _            >> zypp/oe-arch.h
+                 printf "  const Arch Arch_${each_arch} " | tr - _             >> zypp/oe-arch.h
                  echo "(_${each_arch});" | tr - _                              >> zypp/oe-arch.h
                else
-                 echo -n "  const Arch Arch_${each_arch} " | tr - _            >> zypp/oe-arch.h
+                 printf "  const Arch Arch_${each_arch} " | tr - _             >> zypp/oe-arch.h
                  echo "( IdString ( \"${each_arch}\" ) );" | tr - _            >> zypp/oe-arch.h
                fi
        done
index a3242db..55ea241 100644 (file)
@@ -31,12 +31,12 @@ do_install(){
        mkdir -p ${D}${base_bindir}
        mkdir -p ${D}/${baselib}
        mkdir -p ${D}${sysconfdir}/lsb-release.d
-       echo -n "LSB_VERSION=\"core-4.1-noarch:" > ${D}${sysconfdir}/lsb-release
+       printf "LSB_VERSION=\"core-4.1-noarch:" > ${D}${sysconfdir}/lsb-release
 
        if [ "${TARGET_ARCH}" = "i586" ];then
-               echo -n "core-4.1-ia32" >>  ${D}${sysconfdir}/lsb-release
+               printf "core-4.1-ia32" >>  ${D}${sysconfdir}/lsb-release
        else
-               echo -n "core-4.1-${TARGET_ARCH}" >>  ${D}${sysconfdir}/lsb-release
+               printf "core-4.1-${TARGET_ARCH}" >>  ${D}${sysconfdir}/lsb-release
        fi
        echo "\"" >> ${D}${sysconfdir}/lsb-release
        echo "DISTRIB_ID=${DISTRO}" >> ${D}${sysconfdir}/lsb-release
index 2cba9b2..956699c 100755 (executable)
@@ -75,7 +75,7 @@ fi
 image_details $IMAGE
 device_details $(basename $DEVICE)
 
-echo -n "Write $IMAGE to $DEVICE [y/N]? "
+printf "Write $IMAGE to $DEVICE [y/N]? "
 read RESPONSE
 if [ "$RESPONSE" != "y" ]; then
        echo "Write aborted"