Changeset f6d5ca1 in wspkg for arch/arch.deps.sh


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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.