Skip to content

Commit

Permalink
Bash 3 compatibility
Browse files Browse the repository at this point in the history
Motivation:

Mac OS X ships Bash 3, and it does not have an associative array
(declare -A).

Modifications:

Do not use an associative array.

Result:

Can run examples on Mac OS X using run-example.sh
  • Loading branch information
trustin committed May 21, 2014
1 parent e61ad7f commit d4f2488
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions run-example.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#!/bin/bash -e
declare -A EXAMPLE_MAP=(
['spdy-server']='io.netty.example.spdy.server.SpdyServer'
['spdy-client']='io.netty.example.spdy.client.SpdyClient'
EXAMPLE_MAP=(
'spdy-server:io.netty.example.spdy.server.SpdyServer'
'spdy-client:io.netty.example.spdy.client.SpdyClient'
)

EXAMPLE=''
EXAMPLE_CLASS=''
EXAMPLE_ARGS=''
EXAMPLE_ARGS='-D_'
I=0

while [[ $# -gt 0 ]]; do
ARG="$1"
shift
if [[ "$ARG" =~ (^-.+) ]]; then
if [[ -z "$EXAMPLE_ARGS" ]]; then
EXAMPLE_ARGS="$ARG"
else
EXAMPLE_ARGS="$EXAMPLE_ARGS $ARG"
fi
EXAMPLE_ARGS="$EXAMPLE_ARGS $ARG"
else
EXAMPLE="$ARG"
EXAMPLE_CLASS="${EXAMPLE_MAP["$EXAMPLE"]}"
for E in "${EXAMPLE_MAP[@]}"; do
KEY="${E%%:*}"
VAL="${E##*:}"
if [[ "$EXAMPLE" == "$KEY" ]]; then
EXAMPLE_CLASS="$VAL"
break
fi
done
break
fi
done
Expand All @@ -32,14 +35,14 @@ if [[ -z "$EXAMPLE" ]] || [[ -z "$EXAMPLE_CLASS" ]] || [[ $# -ne 0 ]]; then
echo >&2
echo "Available examples:" >&2
echo >&2
for E in "${!EXAMPLE_MAP[@]}"; do
echo " $E"
for E in "${EXAMPLE_MAP[@]}"; do
echo " ${E%%:*}"
done | sort >&2
echo >&2
exit 1
fi

cd "`dirname "$0"`"/example
echo "[INFO] Running: $EXAMPLE ($EXAMPLE_CLASS $EXAMPLE_ARGS)"
exec mvn -nsu compile exec:exec -DargLine.example="$EXAMPLE_ARGS" -DexampleClass="$EXAMPLE_CLASS"
exec mvn -X -nsu compile exec:exec -DargLine.example="$EXAMPLE_ARGS" -DexampleClass="$EXAMPLE_CLASS"

0 comments on commit d4f2488

Please sign in to comment.