Skip to content

Instantly share code, notes, and snippets.

@gsilos
Last active September 4, 2018 14:16
Show Gist options
  • Save gsilos/a1c05bdb6f2e5c9bda5dffaca35ad061 to your computer and use it in GitHub Desktop.
Save gsilos/a1c05bdb6f2e5c9bda5dffaca35ad061 to your computer and use it in GitHub Desktop.
talk to people in bash
#!/bin/bash
# Be paranoid about what is going on...
PS4='${FUNCNAME[0]} (${LINENO}): '
set -x
trap "error_report \$? \$LINENO " ERR
RRCount=0
declare -A ERRHash
# Functions
function error_report() {
code=$1
line=$2
ERRCount=$(expr $ERRCount + $code)
ERRHash[Line $line]="Return Code: $code"
}
function error_care() {
code=$1
message=$2
if [ $code != 0 ]; then
echo "CRITICAL: $message"
exit 1
fi
}
function process() {
...
}
# End Functions
# Main
##############################################
# commands to talk to this person starts here
#############################################
echo "oi cecel, td bem com vc?"
read answer
process answer
echo "ja tomou seu cafe da manha hj?"
read answer
process answer
###########################################
# commands to talk to this person ends here
############################################
for K in "${!ERRHash[@]}";
do
echo $K --- ${ERRHash[$K]};
done
exit $ERRCount
# End Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment