Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

=~ operator is not supported by busybox #3

Open
zhangyoufu opened this issue Jul 3, 2020 · 1 comment
Open

=~ operator is not supported by busybox #3

zhangyoufu opened this issue Jul 3, 2020 · 1 comment

Comments

@zhangyoufu
Copy link

zhangyoufu commented Jul 3, 2020

tested on alpine:latest

PS: I don't like the idea of copy & paste from some ksh script

@zhangyoufu
Copy link
Author

--- a/syslog-redirect.in
+++ b/syslog-redirect.in
@@ -20,25 +20,6 @@ esac
 
 pdie() { echo "$0: ERROR: ${1-}" 1>&2; exit "${2-1}"; }
 
-getopts_want_arg()
-{
-  if [[ $# -lt 2 ]]; then
-    pdie "Option requires an argument: $1"
-  fi
-  if [[ -n ${3:+set} ]]; then
-    if [[ $2 =~ $3 ]]; then
-      : OK
-    else
-      pdie "Invalid value for option: $1: $2"
-    fi
-  fi
-  if [[ -n ${4:+set} ]]; then
-    if [[ $2 =~ $4 ]]; then
-      pdie "Invalid value for option: $1: $2"
-    fi
-  fi
-}
-
 help_p=
 
 while [[ $# -gt 0 ]]; do
@@ -67,7 +48,13 @@ while [[ $# -gt 0 ]]; do
     exit 0
     ;;
   --log-level)
-    getopts_want_arg "$opt" ${1+"$1"} '^[0-7]$'
+    if [ $# -lt 2 ]; then
+      pdie "Option requires an argument: $opt"
+    fi
+    case $1 in
+      [0-7]) ;;
+      *) pdie "Invalid value for option: $opt: $1";;
+    esac
     SYSLOG_REDIRECT_LOG_LEVEL="$1"; shift
     export SYSLOG_REDIRECT_LOG_LEVEL
     ;;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant