Changeset f6d5ca1 in wspkg


Ignore:
Timestamp:
Feb 28, 2019, 8:42:37 PM (3 years ago)
Author:
Ting-Wei Lan <lantw44@…>
Branches:
master
Children:
a2c0986
Parents:
2e6149f
git-author:
Ting-Wei Lan <lantw44@…> (02/28/19 20:27:39)
git-committer:
Ting-Wei Lan <lantw44@…> (02/28/19 20:42:37)
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:
7 edited

Legend:

Unmodified
Added
Removed
  • arch/arch.deps.sh

    r2e6149f rf6d5ca1  
    22
    33msg () {
    4         echo "$@" 1>&2
     4        printf '%s\n' "$1" 1>&2
     5}
     6
     7quote () {
     8        printf \''%s'\' "$(printf '%s' "$1" | sed s,\',\'\"\'\"\',g)"
    59}
    610
     
    2832# pkg_groups_find <group>
    2933pkg_groups_find () {
    30         echo "${pkg_groups_map}" | grep "/$1/" | cut -f 1 -d ' '
     34        printf '%s\n' "${pkg_groups_map}" | grep "/$1/" | cut -f 1 -d ' '
    3135}
    3236
     
    100104        for pkg in ${pkgs}; do
    101105                if [ "${loop_first}" = "1" ]; then
    102                         printf "'%s'" "${pkg}"
     106                        printf '%s' "$(quote "${pkg}")"
    103107                else
    104                         printf " '%s'" "${pkg}"
     108                        printf ' %s' "$(quote "${pkg}")"
    105109                fi
    106110                loop_first=0
  • debian/debian.deps.sh

    r2e6149f rf6d5ca1  
    77for pkg in `cat "${list_file}"`; do
    88        if [ "${loop_first}" = "1" ]; then
    9                 printf "%s" "${pkg}"
     9                printf '%s' "${pkg}"
    1010        else
    11                 printf ", %s" "${pkg}"
     11                printf ', %s' "${pkg}"
    1212        fi
    1313        loop_first=0
  • freebsd/freebsd.deps.sh

    r2e6149f rf6d5ca1  
    1010                pkg_ports="${pkg_ports}@${pkg_flavor}"
    1111        fi
    12         printf "    %s>=a:%s ^%%" "${pkg_name}" "${pkg_ports}"
     12        printf '    %s>=a:%s ^%%' "${pkg_name}" "${pkg_ports}"
    1313done
    1414
  • freebsd/freebsd.install.sh

    r2e6149f rf6d5ca1  
    22
    33msg_and_copy () {
    4     echo "==> Copying $1 to $2" 1>&2
     4    printf '==> Copying %s to %s\n' "$1" "$2" 1>&2
    55    cp -r "$1" "$2"
    66}
    77
    88msg_and_mkdir () {
    9     echo "==> Creating directory $1" 1>&2
     9    printf '==> Creating directory %s\n' "$1" 1>&2
    1010    mkdir -p "$1"
    1111}
    1212
    1313if [ -z "$4" ]; then
    14     echo "Usage: $0 category cat_makefile cat_makefile_inc dir"
    15     echo "Example: "'`'"$0 local local.makefile local.makefile.inc 217' will do"
    16     echo " mkdir -p                 /usr/ports/local"
    17     echo " cp -r local.makefile     /usr/ports/local/Makefile"
    18     echo " cp -r local.makefile.inc /usr/ports/local/Makefile.inc"
    19     echo " cp -r 217                /usr/ports/local"
     14    printf 'Usage: %s category cat_makefile cat_makefile_inc dir\n' "$0"
     15    printf 'Example: %s local local.makefile local.makefile.inc 217 will do\n' "$0"
     16    echo   ' mkdir -p                 /usr/ports/local'
     17    echo   ' cp -r local.makefile     /usr/ports/local/Makefile'
     18    echo   ' cp -r local.makefile.inc /usr/ports/local/Makefile.inc'
     19    echo   ' cp -r 217                /usr/ports/local'
    2020    exit 1
    2121fi
  • freebsd/freebsd.nopkg-setup.sh

    r2e6149f rf6d5ca1  
    1212                        pkg_ports="${pkg_ports} FLAVOR=${pkg_flavor}"
    1313                fi
    14                 printf 'WSPKG_PACKAGE_NAME_%-40s != printf "\\\\r===> Generating package names (%5d/%5d)" 1>\\&2; $(MAKE) -C ${PORTSDIR}/%-48s -V PKGNAMEPREFIX -V PORTNAME -V PKGNAMESUFFIX \\| tr -d "\\\\n"%%' \
     14                printf 'WSPKG_PACKAGE_NAME_%-40s != printf '\''\\\\r===> Generating package names (%5d/%5d)'\'' 1>\\&2; $(MAKE) -C ${PORTSDIR}/%-48s -V PKGNAMEPREFIX -V PORTNAME -V PKGNAMESUFFIX \\| tr -d '\''\\\\n'\''%%' \
    1515                        "${pkg_ports_var}" "${index}" "${count}" "${pkg_ports}"
    1616                index=$(( ${index} + 1 ))
    1717        done )
    18 printf 'WSPKG_PACKAGE_NAME_%-25s != echo 1>\\&2; echo %%' "NULL"
     18printf 'WSPKG_PACKAGE_NAME_%-40s != echo 1>\\&2; echo %%' "NULL"
  • freebsd/freebsd.ports.sh

    r2e6149f rf6d5ca1  
    22
    33msg () {
    4         echo "$@" 1>&2
     4        printf '%s\n' "$1" 1>&2
    55}
    66
  • wspkg-sh/packages-cpp.sh

    r2e6149f rf6d5ca1  
    22
    33toupper () {
    4     echo "$1" | sed 's/^-//' | tr '[:lower:]' '[:upper:]'
     4    printf '%s\n' "$1" | sed 's/^-//' | tr '[:lower:]' '[:upper:]'
    55}
    66
    7 [ -z "$1" ] && echo "Usage: $0 input_file cpp_args" && exit 1
     7[ -z "$1" ] && printf 'Usage: %s input_file cpp_args\n' "$0" && exit 1
    88[ -z "$2" ] && default="yes"
    99
Note: See TracChangeset for help on using the changeset viewer.