[PATCH v2 2/2] implement a LINUX to AIX getopt converter function

Sven Willenbuecher sven.willenbuecher at kuehne-nagel.com
Wed Dec 29 12:38:31 UTC 2021


---
 src/platform/aix.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/platform/aix.sh b/src/platform/aix.sh
index e94ee73..93a120f 100644
--- a/src/platform/aix.sh
+++ b/src/platform/aix.sh
@@ -1,2 +1,46 @@
+#!/usr/bin/sh
+
+quote() (
+  arg=$1
+
+  quoted_arg="'"
+  while true; do
+    case ${arg} in
+      *\'* ) quoted_arg=${quoted_arg}${arg%%\'*}"'\''"
+             arg=${arg#*\'};;
+         * ) break;;
+    esac
+  done
+  [ -z "${arg}" ] || quoted_arg=${quoted_arg}${arg}
+  quoted_arg=${quoted_arg}"'"
+
+  printf %s "${quoted_arg}"
+)
+
+quote_lazy() {
+  case $1 in
+    *[\ \']* ) quote "$1";;
+         *   ) printf %s "${1:-''}";;
+  esac
+}
+
+getopt() (
+  while getopts :ahl:n:o:qQs:uTV opt; do
+    case ${opt} in
+      o ) shortopts=$OPTARG;;
+      * ) true;;
+    esac
+  done
+  getopt_args=
+  shift $((OPTIND - 1))
+  for arg; do
+    quoted_arg=$(quote_lazy "${arg}")
+    quoted_arg=$(quote_lazy "${quoted_arg}")
+    getopt_args="${getopt_args} ${quoted_arg}"
+  done
+  eval command getopt "${shortopts}" "${getopt_args}"
+)
+
+GETOPT=getopt
 VERBOSE_MODE=
 GREP_COLOR_OPTION=
-- 
2.31.1



More information about the Password-Store mailing list