Created
June 5, 2014 09:15
-
-
Save tkuchiki/60683515731f5a55d4ba to your computer and use it in GitHub Desktop.
Term::UI for bash (未完成)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CHOICES=$(echo "hoge foobar piyo") | |
CHOICES="${CHOICES} nothing" | |
NUM=$(echo $CHOICES | wc -w) | |
echo "question?" | |
for i in $(seq 1 $NUM); do | |
echo "${i}) $(echo $CHOICES | cut -d ' ' -f $i)" | |
done | |
echo | |
read -p "Please enter numbers?[$NUM] : " ANSWERS | |
ANSWERS=${ANSWERS:-$NUM} | |
_FS="[, ]" | |
echo "${ANSWERS}" | awk -F "${_FS}" 'BEGIN { OFS=" " } $1 = $1 { print $0 }' | |
for A in $(echo $ANSWERS | awk -F "${_FS}" 'BEGIN { OFS=" " } $1 = $1 { print $0 }'); do | |
declare -i __ANSWER=$A | |
if [ $NUM = $__ANSWER ]; then | |
echo "Canceled" | |
exit 0 | |
elif [ $__ANSWER -le 0 -o $__ANSWER -gt $NUM ]; then | |
echo "Invalid number" | |
exit 1 | |
else | |
echo $CHOICES | cut -d ' ' -f $__ANSWER | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment