diff --git a/sh/tests/solutions/array-selector.sh b/sh/tests/solutions/array-selector.sh new file mode 100755 index 000000000..233ec594c --- /dev/null +++ b/sh/tests/solutions/array-selector.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +IFS=' +' + +COLORS=('red' 'blue' 'green' 'white' 'black') +if [[ ! $1 =~ ^[0-9]+$ ]] || [[ $1 -le 0 ]] || [[ $1 -gt ${#COLORS[@]} ]]; then + echo 'Error' + exit 1 +fi + +POS=$(($1 - 1)) +echo ${COLORS[$POS]} +