Patch-Source: https://github.com/keycloak/keycloak/pull/21124 (backported)

--- a/integration/client-cli/admin-cli/src/main/bin/kcadm.sh
+++ b/integration/client-cli/admin-cli/src/main/bin/kcadm.sh
@@ -1,32 +1,27 @@
 #!/bin/sh
-case "`uname`" in
+case "$(uname)" in
     CYGWIN*)
-        CFILE = `cygpath "$0"`
-        RESOLVED_NAME=`readlink -f "$CFILE"`
+        CFILE="$(cygpath "$0")"
+        RESOLVED_NAME="$(readlink -f "$CFILE")"
         ;;
     Darwin*)
-        RESOLVED_NAME=`readlink "$0"`
+        RESOLVED_NAME="$(readlink "$0")"
         ;;
-    FreeBSD)
-        RESOLVED_NAME=`readlink -f "$0"`
+    FreeBSD | Linux)
+        RESOLVED_NAME="$(readlink -f "$0")"
         ;;
-    Linux)
-        RESOLVED_NAME=`readlink -f "$0"`
-        ;;
 esac
 
-if [ "x$RESOLVED_NAME" = "x" ]; then
-    RESOLVED_NAME="$0"
-fi
+RESOLVED_NAME="${RESOLVED_NAME:-"$0"}"
 
-DIRNAME=`dirname "$RESOLVED_NAME"`
+DIRNAME="$(dirname "$RESOLVED_NAME")"
 
-if [ "x$JAVA" = "x" ]; then
-    if [ "x$JAVA_HOME" != "x" ]; then
+if [ -z "$JAVA" ]; then
+    if [ -n "$JAVA_HOME" ]; then
         JAVA="$JAVA_HOME/bin/java"
     else
         JAVA="java"
     fi
 fi
 
-"$JAVA" $KC_OPTS -cp $DIRNAME/client/keycloak-admin-cli-${project.version}.jar --add-opens=java.base/java.security=ALL-UNNAMED -Dkc.lib.dir=$DIRNAME/client/lib org.keycloak.client.admin.cli.KcAdmMain "$@"
+exec "$JAVA" $KC_OPTS -cp $DIRNAME/client/keycloak-admin-cli-${project.version}.jar --add-opens=java.base/java.security=ALL-UNNAMED -Dkc.lib.dir=$DIRNAME/client/lib org.keycloak.client.admin.cli.KcAdmMain "$@"
--- a/integration/client-cli/client-registration-cli/src/main/bin/kcreg.sh
+++ b/integration/client-cli/client-registration-cli/src/main/bin/kcreg.sh
@@ -1,31 +1,26 @@
 #!/bin/sh
-case "`uname`" in
+case "$(uname)" in
     CYGWIN*)
-        CFILE = `cygpath "$0"`
-        RESOLVED_NAME=`readlink -f "$CFILE"`
+        CFILE="$(cygpath "$0")"
+        RESOLVED_NAME="$(readlink -f "$CFILE")"
         ;;
     Darwin*)
-        RESOLVED_NAME=`readlink "$0"`
+        RESOLVED_NAME="$(readlink "$0")"
         ;;
-    FreeBSD)
-        RESOLVED_NAME=`readlink -f "$0"`
+    FreeBSD | Linux)
+        RESOLVED_NAME="$(readlink -f "$0")"
         ;;
-    Linux)
-        RESOLVED_NAME=`readlink -f "$0"`
-        ;;
 esac
 
-if [ "x$RESOLVED_NAME" = "x" ]; then
-    RESOLVED_NAME="$0"
-fi
+RESOLVED_NAME="${RESOLVED_NAME:-"$0"}"
 
-if [ "x$JAVA" = "x" ]; then
-    if [ "x$JAVA_HOME" != "x" ]; then
+if [ -z "$JAVA" ]; then
+    if [ -n "$JAVA_HOME" ]; then
         JAVA="$JAVA_HOME/bin/java"
     else
         JAVA="java"
     fi
 fi
 
-DIRNAME=`dirname "$RESOLVED_NAME"`
-"$JAVA" $KC_OPTS -cp $DIRNAME/client/keycloak-client-registration-cli-${project.version}.jar --add-opens=java.base/java.security=ALL-UNNAMED -Dkc.lib.dir=$DIRNAME/client/lib org.keycloak.client.registration.cli.KcRegMain "$@"
+DIRNAME="$(dirname "$RESOLVED_NAME")"
+exec "$JAVA" $KC_OPTS -cp $DIRNAME/client/keycloak-client-registration-cli-${project.version}.jar --add-opens=java.base/java.security=ALL-UNNAMED -Dkc.lib.dir=$DIRNAME/client/lib org.keycloak.client.registration.cli.KcRegMain "$@"
--- a/quarkus/dist/src/main/content/bin/kc.sh
+++ b/quarkus/dist/src/main/content/bin/kc.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 case "$(uname)" in
     CYGWIN*)
@@ -17,9 +17,7 @@
         ;;
 esac
 
-if [ "x$RESOLVED_NAME" = "x" ]; then
-    RESOLVED_NAME="$0"
-fi
+RESOLVED_NAME="${RESOLVED_NAME:-"$0"}"
 
 GREP="grep"
 DIRNAME="$(dirname "$RESOLVED_NAME")"
@@ -49,7 +47,7 @@
     case "$1" in
       --debug)
           DEBUG_MODE=true
-          if [ -n "$2" ] && [[ "$2" =~ ^[0-9]+$ ]]; then
+          if [ -n "$2" ] && expr "$2" : '[0-9]\+$' >/dev/null; then
               DEBUG_PORT=$2
               shift
           fi
@@ -59,22 +57,18 @@
           break
           ;;
       *)
-          if [[ $1 = --* || ! $1 =~ ^-D.* ]]; then
-            if [[ "$1" = "start-dev" ]]; then
-              CONFIG_ARGS="$CONFIG_ARGS --profile=dev $1"
-            else
-              CONFIG_ARGS="$CONFIG_ARGS $1"
-            fi
-          else
-            SERVER_OPTS="$SERVER_OPTS $1"
-          fi
+          case "$1" in
+            start-dev) CONFIG_ARGS="$CONFIG_ARGS --profile=dev $1";;
+            -D*) SERVER_OPTS="$SERVER_OPTS $1";;
+            *) CONFIG_ARGS="$CONFIG_ARGS $1";;
+          esac
           ;;
     esac
     shift
 done
 
-if [ "x$JAVA" = "x" ]; then
-    if [ "x$JAVA_HOME" != "x" ]; then
+if [ -z "$JAVA" ]; then
+    if [ -n "$JAVA_HOME" ]; then
         JAVA="$JAVA_HOME/bin/java"
     else
         JAVA="java"
@@ -84,21 +78,21 @@
 #
 # Specify options to pass to the Java VM.
 #
-if [ "x$JAVA_OPTS" = "x" ]; then
+if [ -z "$JAVA_OPTS" ]; then
    JAVA_OPTS="-Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.err.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8"
 else
    echo "JAVA_OPTS already set in environment; overriding default settings with values: $JAVA_OPTS"
 fi
 
 # See also https://github.com/wildfly/wildfly-core/blob/7e5624cf92ebe4b64a4793a8c0b2a340c0d6d363/core-feature-pack/common/src/main/resources/content/bin/common.sh#L57-L60
-if [ "x$JAVA_ADD_OPENS" = "x" ]; then
+if [ -z "$JAVA_ADD_OPENS" ]; then
    JAVA_ADD_OPENS="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED"
 else
    echo "JAVA_ADD_OPENS already set in environment; overriding default settings with values: $JAVA_ADD_OPENS"
 fi
 JAVA_OPTS="$JAVA_OPTS $JAVA_ADD_OPENS"
 
-if [ "x$JAVA_OPTS_APPEND" != "x" ]; then
+if [ -n "$JAVA_OPTS_APPEND" ]; then
   echo "Appending additional Java properties to JAVA_OPTS: $JAVA_OPTS_APPEND"
   JAVA_OPTS="$JAVA_OPTS $JAVA_OPTS_APPEND"
 fi
@@ -106,7 +100,7 @@
 # Set debug settings if not already set
 if [ "$DEBUG_MODE" = "true" ]; then
     DEBUG_OPT="$(echo "$JAVA_OPTS" | $GREP "\-agentlib:jdwp")"
-    if [ "x$DEBUG_OPT" = "x" ]; then
+    if [ -z "$DEBUG_OPT" ]; then
         JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=$DEBUG_SUSPEND"
     else
         echo "Debug already enabled in JAVA_OPTS, ignoring --debug argument"
@@ -120,13 +114,12 @@
   echo "Using JAVA_RUN_OPTS: $JAVA_RUN_OPTS"
 fi
 
-if [[ (! $CONFIG_ARGS = *"--optimized"*) ]] && [[ ! "$CONFIG_ARGS" == " build"* ]] && [[ ! "$CONFIG_ARGS" == *"-h" ]] && [[ ! "$CONFIG_ARGS" == *"--help"* ]]; then
-    eval "'$JAVA'" -Dkc.config.build-and-exit=true $JAVA_RUN_OPTS
-    EXIT_CODE=$?
+case "$CONFIG_ARGS" in
+  " build"* | *--optimized* | *-h | *--help*) ;;
+  *)
+    eval "'$JAVA'" -Dkc.config.build-and-exit=true $JAVA_RUN_OPTS || exit $?
     JAVA_RUN_OPTS="-Dkc.config.built=true $JAVA_RUN_OPTS"
-    if [ $EXIT_CODE != 0 ]; then
-      exit $EXIT_CODE
-    fi
-fi
+    ;;
+esac
 
 eval exec "'$JAVA'" $JAVA_RUN_OPTS
