aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2018-01-19 00:28:31 +0100
committerKate Ward <kate.ward@forestent.com>2018-01-19 00:28:31 +0100
commitd2ecc883a5ab4827c416934a2f2dc7e032b7acdd (patch)
tree8ca344d464e17f5b7c6d66a5cf91960d676ec8b2
parente38d04c0d755bcbca69a602d28bd36f54757e4a1 (diff)
parent5bc87c6a45a5eb988c275e5c18c72f90e96c241c (diff)
downloadshflags-d2ecc883a5ab4827c416934a2f2dc7e032b7acdd.tar.gz
Merge branch 'master' of github.com:kward/shflags
-rw-r--r--.travis.yml2
-rwxr-xr-xlib/versions55
-rw-r--r--shflags2
-rwxr-xr-xshflags_public_test.sh2
-rw-r--r--shflags_test_helpers18
5 files changed, 50 insertions, 29 deletions
diff --git a/.travis.yml b/.travis.yml
index 762e19c..f773ce9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,5 +22,5 @@ matrix:
- os: linux
script:
# Run the source through ShellCheck (http://www.shellcheck.net).
- - shellcheck gen_test_report.sh *_test.sh
+ - shellcheck *_test.sh
- shellcheck -s sh shflags shflags_test_helpers
diff --git a/lib/versions b/lib/versions
index 47575e7..7c3badd 100755
--- a/lib/versions
+++ b/lib/versions
@@ -18,7 +18,7 @@
ARGV0=`basename "$0"`
LSB_RELEASE='/etc/lsb-release'
-VERSIONS_SHELLS="ash /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/sh /bin/zsh"
+VERSIONS_SHELLS='ash /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh /bin/sh /usr/xpg4/bin/sh /sbin/sh'
true; TRUE=$?
false; FALSE=$?
@@ -123,12 +123,8 @@ versions_shellVersion() {
shell_present_=${FALSE}
case "${shell_}" in
- ash)
- [ -x '/bin/busybox' ] && shell_present_=${TRUE}
- ;;
- *)
- [ -x "${shell_}" ] && shell_present_=${TRUE}
- ;;
+ ash) [ -x '/bin/busybox' ] && shell_present_=${TRUE} ;;
+ *) [ -x "${shell_}" ] && shell_present_=${TRUE} ;;
esac
if [ ${shell_present_} -eq ${FALSE} ]; then
echo 'not installed'
@@ -137,16 +133,19 @@ versions_shellVersion() {
version_=''
case ${shell_} in
+ /sbin/sh) ;; # SunOS
+ /usr/xpg4/bin/sh)
+ version_=`versions_shell_xpg4 "${shell_}"`
+ ;; # SunOS
*/sh)
- # TODO(kward): fix this
- ## This could be one of any number of shells. Try until one fits.
- #version_=`versions_shell_bash ${shell_}`
- ## dash cannot be self determined yet.
- #[ -z "${version_}" ] && version_=`versions_shell_ksh ${shell_}`
- ## pdksh is covered in versions_shell_ksh().
- #[ -z "${version_}" ] && version_=`versions_shell_zsh ${shell_}`
- # TODO(20180115:kward) If ${UNAME_S} is SunOS, recommend implementing:
- # $ ln -sf /usr/xpg4/bin/sh /bin/sh
+ # This could be one of any number of shells. Try until one fits.
+ version_=''
+ [ -z "${version_}" ] && version_=`versions_shell_bash "${shell_}"`
+ # dash cannot be self determined yet
+ [ -z "${version_}" ] && version_=`versions_shell_ksh "${shell_}"`
+ # pdksh is covered in versions_shell_ksh()
+ [ -z "${version_}" ] && version_=`versions_shell_xpg4 "${shell_}"`
+ [ -z "${version_}" ] && version_=`versions_shell_zsh "${shell_}"`
;;
ash) version_=`versions_shell_ash "${shell_}"` ;;
*/bash) version_=`versions_shell_bash "${shell_}"` ;;
@@ -171,7 +170,7 @@ versions_shell_ash() {
}
versions_shell_bash() {
- $1 --version 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/'
+ $1 --version : 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/'
}
versions_shell_dash() {
@@ -186,9 +185,13 @@ versions_shell_ksh() {
versions_version_=''
# Try a few different ways to figure out the version.
- if versions_version_=`${versions_shell_} --version : 2>&1`; then
+ versions_version_=`${versions_shell_} --version : 2>&1`
+ # shellcheck disable=SC2181
+ if [ $? -eq 0 ]; then
versions_version_=`echo "${versions_version_}" \
|sed 's/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*/\1/'`
+ else
+ versions_version_=''
fi
if [ -z "${versions_version_}" ]; then
_versions_have_strings
@@ -211,15 +214,27 @@ versions_shell_pdksh() {
|sed -e 's/.*PD KSH \(.*\)/\1/;s/ /-/g'
}
+versions_shell_xpg4() {
+ _versions_have_strings
+ strings "$1" 2>&1 \
+ |grep 'Version' \
+ |sed -e 's/^@(#)Version //'
+}
+
versions_shell_zsh() {
versions_shell_=$1
# Try a few different ways to figure out the version.
# shellcheck disable=SC2016
versions_version_=`echo 'echo ${ZSH_VERSION}' |${versions_shell_}`
-
if [ -z "${versions_version_}" ]; then
- versions_version_=`${versions_shell_} --version 2>&1 |awk '{print $2}'`
+ versions_version_=`${versions_shell_} --version : 2>&1`
+ # shellcheck disable=SC2181
+ if [ $? -eq 0 ]; then
+ versions_version_=`echo "${versions_version_}" |awk '{print $2}'`
+ else
+ versions_version_=''
+ fi
fi
echo "${versions_version_}"
diff --git a/shflags b/shflags
index d8b1dff..7232940 100644
--- a/shflags
+++ b/shflags
@@ -83,6 +83,8 @@
# - lists of strings are space separated, and a null value is the '~' char.
#
### ShellCheck (http://www.shellcheck.net/)
+# expr may be antiquated, but it is the only solution in some cases.
+# shellcheck disable=SC2003
# $() are not fully portable (POSIX != portable).
# shellcheck disable=SC2006
# [ p -a q ] are well defined enough (vs [ p ] && [ q ]).
diff --git a/shflags_public_test.sh b/shflags_public_test.sh
index e070be0..72db11f 100755
--- a/shflags_public_test.sh
+++ b/shflags_public_test.sh
@@ -12,6 +12,8 @@
### ShellCheck (http://www.shellcheck.net/)
# Disable source following.
# shellcheck disable=SC1090,SC1091
+# $() are not fully portable (POSIX != portable).
+# shellcheck disable=SC2006
# These variables will be overridden by the test helpers.
expectedF="${TMPDIR:-/tmp}/expected"
diff --git a/shflags_test_helpers b/shflags_test_helpers
index d25976e..77dbf28 100644
--- a/shflags_test_helpers
+++ b/shflags_test_helpers
@@ -13,6 +13,10 @@
# shellcheck disable=SC1090,SC1091
# $() are not fully portable (POSIX != portable).
# shellcheck disable=SC2006
+# Arrays are not available in all shells.
+# shellcheck disable=SC2089
+# Exporting variables shouldn't impact their contents.
+# shellcheck disable=SC2090
# Disagree with [ p ] && [ q ] vs [ p -a -q ] recommendation.
# shellcheck disable=SC2166
@@ -40,15 +44,13 @@ TH_SHFLAGS=${SHFLAGS_INC:-./shflags}; export TH_SHFLAGS
# Path to shUnit2 library. Can be overridden by setting SHUNIT_INC.
TH_SHUNIT=${SHUNIT_INC:-lib/shunit2}; export TH_SHUNIT
-TH_BOOL_VALID='true t 0 false f 1'
-TH_BOOL_INVALID='123 123.0 invalid'
-export TH_BOOL_VALID TH_BOOL_INVALID
+TH_BOOL_VALID='true t 0 false f 1'; export TH_BOOL_VALID
+TH_BOOL_INVALID='123 123.0 invalid'; export TH_BOOL_INVALID
TH_FLOAT_VALID='-1234.0 -1.0 -.123 0.0 0. .123 1.0 1234.0'
-TH_FLOAT_INVALID='true false 1.2.3 -1.2.3 ""'
-export TH_FLOAT_VALID TH_FLOAT_INVALID
-TH_INT_VALID='-1234 -1 0 1 1234'
-TH_INT_INVALID='true false -1.0 -.123 0.0 .123 1.0 ""'
-export TH_INT_VALID TH_INT_INVALID
+export TH_FLOAT_VALID
+TH_FLOAT_INVALID='true false 1.2.3 -1.2.3 ""'; export TH_FLOAT_INVALID
+TH_INT_VALID='-1234 -1 0 1 1234'; export TH_INT_VALID
+TH_INT_INVALID='true false -1.0 -.123 0.0 .123 1.0 ""'; export TH_INT_INVALID
#
# Test helper functions.