Created
August 8, 2013 19:04
-
-
Save rhwood/6187653 to your computer and use it in GitHub Desktop.
Sample bash/sh code to prompt a user for a complex answer using vi.
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/sh | |
INSTRUCTIONS="-- This line, and those below, will be ignored. -- | |
Add a business case. The business case should be described briefly in a single | |
line on the first line, followed by a more detailed description on the | |
following lines." | |
CONTENT="" | |
until [[ ${CONTENT} =~ [[:alnum:]] ]] ; do | |
TMP_CONTENT=$( mktemp ) | |
echo "" > ${TMP_CONTENT} | |
echo "${INSTRUCTIONS}" >> ${TMP_CONTENT} | |
vi ${TMP_CONTENT} | |
CONTENT=$( cat ${TMP_CONTENT} ) | |
CONTENT="${CONTENT%%${INSTRUCTIONS}}" | |
if [[ ! ${CONTENT} =~ [[:alnum:]] ]] ; then | |
read -p "No business case entered. Continue or Abort (C/A)? [Abort]: " RESPONSE | |
if [[ -z ${RESPONSE} || ! ${RESPONSE} =~ ^[cC] ]] ; then | |
exit | |
fi | |
fi | |
rm ${TMP_CONTENT} | |
done | |
echo "${CONTENT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment