Changeset f6d5ca1 in wspkg for freebsd/freebsd.install.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
  • 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
Note: See TracChangeset for help on using the changeset viewer.