Changeset c0ba16c in wspkg-data


Ignore:
Timestamp:
Feb 28, 2019, 9:33:06 PM (3 years ago)
Author:
Ting-Wei Lan <lantw44@…>
Branches:
master
Children:
637ce02
Parents:
78e7743
git-author:
Ting-Wei Lan <lantw44@…> (02/28/19 20:42:44)
git-committer:
Ting-Wei Lan <lantw44@…> (02/28/19 21:33:06)
Message:

Use 'printf' to print non-constant strings in shell scripts

It is unsafe to use 'echo' with strings with variable substitutions.
Different 'echo' implementations may accept different options, and they
can interpret strings with escape characters in different ways. The
behavior of 'printf' is much more consistent so it should be preferred.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 217-mrtg.sh

    r78e7743 rc0ba16c  
    22
    33write_string_to_fd () {
    4         fd="$1"
    5         shift
    6         echo "$@" 1>&"$fd"
     4        printf '%s\n' "$2" 1>&"$1"
    75}
    86
    97write_stdin_to_fd () {
    10         fd="$1"
    11         shift
    12         cat 1>&"$fd"
     8        cat 1>&"$1"
    139}
    1410
    1511echo_cmd () {
    16         printf "\033[1;33mRunning command => \033[m"
    17         echo "$@"
     12        printf '\033[1;33mRunning command =>\033[m'
     13        for arg in "$@"; do
     14                printf ' %s' "${arg}"
     15        done
     16        printf '\n'
    1817        "$@"
    19         echo
     18        printf '\n'
    2019}
    2120
  • build.sh

    r78e7743 rc0ba16c  
    22
    33if [ -z "$WSPKGDIR" ]; then
    4     printf "\033[1;31mWSPKGDIR is not defined so I cannot build package for you :(\033[m\n"
     4    printf '\033[1;31mWSPKGDIR is not defined so I cannot build package for you :(\033[m\n'
    55    if [ -f "../wspkg/wspkg-mk/packages.mk" ]; then
    6         echo "You may want to try WSPKGDIR=\"$(dirname "`pwd`")/wspkg\" $0"
     6        printf 'You may want to try WSPKGDIR="%s/wspkg" %s\n' "$(dirname "$(pwd)")" "$0"
    77    elif [ -f "/usr/share/wspkg/wspkg-mk/packages.mk" ]; then
    8         echo "You may want to try WSPKGDIR=/usr/share/wspkg $0"
     8        printf 'You may want to try WSPKGDIR=/usr/share/wspkg %s\n' "$0"
    99    elif [ -f "/usr/pkg/share/wspkg/wspkg-mk/packages.mk" ]; then
    10         echo "You may want to try WSPKGDIR=/usr/pkg/share/wspkg $0"
     10        printf 'You may want to try WSPKGDIR=/usr/pkg/share/wspkg %s\n' "$0"
    1111    elif [ -f "/usr/local/share/wspkg/wspkg-mk/packages.mk" ]; then
    12         echo "You may want to try WSPKGDIR=/usr/local/share/wspkg $0"
     12        printf 'You may want to try WSPKGDIR=/usr/local/share/wspkg %s\n' "$0"
    1313    fi
    1414    exit 1
    1515fi
    1616
    17 [ -z "$1" ] && echo "Usage: $0 makefile" && exit 1
     17[ -z "$1" ] && printf 'Usage: %s makefile\n' "$0" && exit 1
    1818if [ -d "$1" ]; then
    1919    makefile="${1}.mk"
     
    2424
    2525: ${MAKE:="make"}
    26 printf "\033[1;33mRunning\033[m: %s -f \"%s\" WSPKGDIR=\"%s\" " "${MAKE}" "$makefile" "$WSPKGDIR"
    27 echo "$@"
    28 echo ""
     26printf '\033[1;33mRunning\033[m: %s -f "%s" WSPKGDIR="%s"' "${MAKE}" "$makefile" "$WSPKGDIR"
     27for arg in "$@"; do
     28    printf ' %s' "$arg"
     29done
     30printf '\n\n'
    2931if ${MAKE} -f "$makefile" WSPKGDIR="$WSPKGDIR" "$@"; then
    3032    printf '\n\033[1;32mDone! ;-)\033[m\n'
  • wsbsd.files/patches-apply.sh

    r78e7743 rc0ba16c  
    33: ${PORTSDIR:="/usr/ports"}
    44[ '!' -d "${PORTSDIR}/.svn" ] && \
    5     echo "${PORTSDIR} is not a svn checkout" && exit 1
     5    printf '%s is not a svn checkout\n' "${PORTSDIR}" && exit 1
    66
    77shdir="$(realpath "$(dirname "$0")")"
     
    1313for patch_file in "${patchdir}"/*; do
    1414        if patch -s -C -f -p0 < "${patch_file}"; then
    15                 echo "==> Applying ${patch_file}"
     15                printf '==> Applying %s\n' "${patch_file}"
    1616                patch -s -N -p0 < "${patch_file}"
    1717        else
    18                 echo "==> Skipping ${patch_file}"
     18                printf '==> Skipping %s\n' "${patch_file}"
    1919        fi
    2020done
  • wsbsd.files/patches-update.sh

    r78e7743 rc0ba16c  
    33: ${PORTSDIR:="/usr/ports"}
    44[ '!' -d "${PORTSDIR}/.svn" ] && \
    5     echo "${PORTSDIR} is not a svn checkout" && exit 1
     5    printf '%s is not a svn checkout\n' "${PORTSDIR}" && exit 1
    66
    77shdir="$(realpath "$(dirname "$0")")"
     
    1111
    1212cd ${PORTSDIR}
    13 echo "==> Running svn status ..."
     13echo '==> Running svn status ...'
    1414svn status | sed -e '/^?/d' -e 's#^[A-Z]* *\([^/]*\/[^/]*\)\(/.*\)*$#\1#' | \
    1515    sort | uniq | (
    1616    while read oneline; do
    17         echo "==> Generating patch for ${oneline}"
    18         patch_name="$(echo "${oneline}" | tr '/' '_')"
     17        printf '==> Generating patch for %s\n' "${oneline}"
     18        patch_name="$(printf '%s\n' "${oneline}" | tr '/' '_')"
    1919        svn diff --patch-compatible "${oneline}" \
    2020            > "${patchdir}/${patch_name}.patch"
Note: See TracChangeset for help on using the changeset viewer.