lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 75fa2b9 2/5: Improve shell quoting


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 75fa2b9 2/5: Improve shell quoting
Date: Sat, 21 Apr 2018 13:56:27 -0400 (EDT)

branch: master
commit 75fa2b9f375c6f5ae23b81d541b85663ecccb0d7
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Improve shell quoting
    
    Replaced many instances of
      printf "...
    with
      printf '...
    in particular favoring this quoting style:
      printf '  foo is %s\n  bar is %s\n' "$foo" "$bar"
    with 'FORMAT' in single quotes and "ARGUMENTS" in double quotes.
    
    This is far better than shellcheck's recommendation:
      printf "Hello, world!\n"
                           ^-- SC1117:
        Backslash is literal in "\n". Prefer explicit escaping: "\\n".
    which clashes horribly with the C idiom:
      printf "Hello, world?!\\n"   # prints a newline
      printf("Hello, world?!\\n"); # prints a backslash and an 'n'
---
 check_git_setup.sh        | 44 ++++++++++++++++++++++----------------------
 test_coding_rules_test.sh | 10 +++++-----
 workhorse.make            | 32 ++++++++++++++++----------------
 3 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/check_git_setup.sh b/check_git_setup.sh
index 1d6e046..90fa2b5 100755
--- a/check_git_setup.sh
+++ b/check_git_setup.sh
@@ -26,9 +26,9 @@
 
 cd $(dirname $(readlink -f "$0")) || print "Cannot cd"
 toplevel=$(git rev-parse --show-toplevel)
-printf "'%s' is current directory\n" "$PWD"
-printf "'%s' is git toplevel directory\n" "$toplevel"
-[ "$PWD" = "$toplevel" ] || { printf "fail: PWD is not toplevel\n"; exit 1; }
+printf '"%s" is current directory\n' "$PWD"
+printf '"%s" is git toplevel directory\n' "$toplevel"
+[ "$PWD" = "$toplevel" ] || { printf 'fail: PWD is not toplevel\n'; exit 1; }
 
 # For msw (cygwin) only, force correct permissions, and make sure
 #'core.filemode' is "false". See:
@@ -36,21 +36,21 @@ printf "'%s' is git toplevel directory\n" "$toplevel"
 
 case $(uname -s) in
   (CYGWIN*)
-    printf "cygwin detected\n"
-    printf "forcing correct permissions "
+    printf 'cygwin detected\n'
+    printf 'forcing correct permissions '
       for d in . gwc; do (\
-           printf "%s..." "$d" \
+           printf '%s...' "$d" \
         && find ./$d -maxdepth 1 -type f -not -name '*.sh' -not -name '*.sed' 
| xargs chmod -x \
       )done; \
-    printf "all permissions forced\n"
+    printf 'all permissions forced\n'
     git config core.filemode false
     ;;
   (*)
-    printf "cygwin not detected--assuming OS is POSIX\n"
+    printf 'cygwin not detected--assuming OS is POSIX\n'
     ;;
 esac
 
-printf "core.filemode is '%s'\n" $(git config --get-all core.filemode)
+printf 'core.filemode is "%s"\n' "$(git config --get-all core.filemode)"
 
 # Make sure the hooks in the repository's hooks/ directory are used.
 #
@@ -59,21 +59,21 @@ printf "core.filemode is '%s'\n" $(git config --get-all 
core.filemode)
 
 case "$(readlink -f .git/hooks)" in
   ("$PWD/.git/hooks")
-    mv .git/hooks .git/hooks-orig && printf "moved" || printf "didn't move"
-    printf " old hooks/ directory to hooks-orig/\n"
-    printf "creating symlink\n"
+    mv .git/hooks .git/hooks-orig && printf 'moved' || printf 'failed to move'
+    printf ' old hooks/ directory to hooks-orig/\n'
+    printf 'creating symlink\n'
     ln --symbolic --force --no-dereference ../hooks .git
     ;;
 esac
 
 # So many readlink options, so little time...just use them all.
 
-printf "testing .git/hooks symlink:\n"
-printf "  readlink   : '%s'\n" "$(readlink    .git/hooks)"
-printf "  readlink -e: '%s'\n" "$(readlink -e .git/hooks)"
-printf "  readlink -f: '%s'\n" "$(readlink -f .git/hooks)"
-printf "  readlink -m: '%s'\n" "$(readlink -m .git/hooks)"
-printf "  expected   : '%s'\n" "$PWD"/hooks
+printf 'testing .git/hooks symlink:\n'
+printf '  readlink   : "%s"\n' "$(readlink    .git/hooks)"
+printf '  readlink -e: "%s"\n' "$(readlink -e .git/hooks)"
+printf '  readlink -f: "%s"\n' "$(readlink -f .git/hooks)"
+printf '  readlink -m: "%s"\n' "$(readlink -m .git/hooks)"
+printf '  expected   : "%s"\n' "$PWD"/hooks
 
 # Verify that .git/hooks is a symlink to the repository's hooks/
 # directory, and that it contains an executable pre-commit hook.
@@ -81,16 +81,16 @@ printf "  expected   : '%s'\n" "$PWD"/hooks
 
 case "$(readlink -f .git/hooks)" in
   ("$PWD/hooks")
-    [ -x ".git/hooks/pre-commit" ] || { printf "fail: missing hook\n"; exit 2; 
}
-    printf "git hooks directory is properly symlinked\n"
+    [ -x ".git/hooks/pre-commit" ] || { printf 'fail: missing hook\n'; exit 2; 
}
+    printf 'git hooks directory is properly symlinked\n'
     exit 0
     ;;
   ("$PWD/.git/hooks")
-    printf "attempted hooks/ change failed\n"
+    printf 'attempted hooks/ change failed\n'
     exit 3
     ;;
   (*)
-    printf "unanticipated error\n"
+    printf 'unanticipated error\n'
     exit 4
     ;;
 esac
diff --git a/test_coding_rules_test.sh b/test_coding_rules_test.sh
index 19b96ec..2308b26 100755
--- a/test_coding_rules_test.sh
+++ b/test_coding_rules_test.sh
@@ -42,7 +42,7 @@ good_copyright="...Copyright (C)...$(date -u +'%Y')..."
 
 good_url="...http://savannah.nongnu.org/projects/lmi...";
 
-boilerplate=$(printf "%s\n%s" "$good_copyright" "$good_url")
+boilerplate=$(printf '%s\n%s' "$good_copyright" "$good_url")
 
 # Files in general.
 
@@ -138,25 +138,25 @@ $boilerplate
 Spaces are permitted; they  can   be    consecutive.
 EOF
 
-ascii_ff=$(printf "\f")
+ascii_ff=$(printf '\f')
 cat >eraseme_whitespace_001 <<EOF
 $boilerplate
 $ascii_ff
 EOF
 
-ascii_cr=$(printf "\r")
+ascii_cr=$(printf '\r')
 cat >eraseme_whitespace_002 <<EOF
 $boilerplate
 $ascii_cr
 EOF
 
-ascii_ht=$(printf "\t")
+ascii_ht=$(printf '\t')
 cat >eraseme_whitespace_003 <<EOF
 $boilerplate
 $ascii_ht
 EOF
 
-ascii_vt=$(printf "\v")
+ascii_vt=$(printf '\v')
 cat >eraseme_whitespace_004 <<EOF
 $boilerplate
 $ascii_vt
diff --git a/workhorse.make b/workhorse.make
index f233632..b0f2ed5 100644
--- a/workhorse.make
+++ b/workhorse.make
@@ -1465,20 +1465,20 @@ clean_edg:
 
 .PHONY: show_flags
 show_flags:
-       @printf "gcc_version             = '%s'\n" "$(gcc_version)"
-       @printf "gnu_cpp_version         = '%s'\n" "$(gnu_cpp_version)"
-       @printf "gnu_cxx_version         = '%s'\n" "$(gnu_cxx_version)"
-       @printf "ALL_CPPFLAGS            = '%s'\n" "$(ALL_CPPFLAGS)"
-       @printf "ALL_CFLAGS              = '%s'\n" "$(ALL_CFLAGS)"
-       @printf "ALL_CXXFLAGS            = '%s'\n" "$(ALL_CXXFLAGS)"
-       @printf "ALL_ARFLAGS             = '%s'\n" "$(ALL_ARFLAGS)"
-       @printf "ALL_LDFLAGS             = '%s'\n" "$(ALL_LDFLAGS)"
-       @printf "ALL_RCFLAGS             = '%s'\n" "$(ALL_RCFLAGS)"
-       @printf "srcdir                  = '%s'\n" "$(srcdir)"
-       @printf "all_include_directories = '%s'\n" "$(all_include_directories)"
-       @printf "all_source_directories  = '%s'\n" "$(all_source_directories)"
-       @printf "wx_include_paths        = '%s'\n" "$(wx_include_paths)"
-       @printf "wx_libraries            = '%s'\n" "$(wx_libraries)"
-       @printf "wx_library_paths        = '%s'\n" "$(wx_library_paths)"
-       @printf "wx_predefinitions       = '%s'\n" "$(wx_predefinitions)"
+       @printf 'gcc_version             = "%s"\n' "$(gcc_version)"
+       @printf 'gnu_cpp_version         = "%s"\n' "$(gnu_cpp_version)"
+       @printf 'gnu_cxx_version         = "%s"\n' "$(gnu_cxx_version)"
+       @printf 'ALL_CPPFLAGS            = "%s"\n' "$(ALL_CPPFLAGS)"
+       @printf 'ALL_CFLAGS              = "%s"\n' "$(ALL_CFLAGS)"
+       @printf 'ALL_CXXFLAGS            = "%s"\n' "$(ALL_CXXFLAGS)"
+       @printf 'ALL_ARFLAGS             = "%s"\n' "$(ALL_ARFLAGS)"
+       @printf 'ALL_LDFLAGS             = "%s"\n' "$(ALL_LDFLAGS)"
+       @printf 'ALL_RCFLAGS             = "%s"\n' "$(ALL_RCFLAGS)"
+       @printf 'srcdir                  = "%s"\n' "$(srcdir)"
+       @printf 'all_include_directories = "%s"\n' "$(all_include_directories)"
+       @printf 'all_source_directories  = "%s"\n' "$(all_source_directories)"
+       @printf 'wx_include_paths        = "%s"\n' "$(wx_include_paths)"
+       @printf 'wx_libraries            = "%s"\n' "$(wx_libraries)"
+       @printf 'wx_library_paths        = "%s"\n' "$(wx_library_paths)"
+       @printf 'wx_predefinitions       = "%s"\n' "$(wx_predefinitions)"
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]