Skip to content

Instantly share code, notes, and snippets.

@rhwood
Created August 8, 2013 19:04
Show Gist options
  • Save rhwood/6187653 to your computer and use it in GitHub Desktop.
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.
#!/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