Skip to content

Instantly share code, notes, and snippets.

@9oelM
Last active January 7, 2022 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9oelM/ce9eab16caba1a19472be94464dbfdf7 to your computer and use it in GitHub Desktop.
Save 9oelM/ce9eab16caba1a19472be94464dbfdf7 to your computer and use it in GitHub Desktop.
Get bible verses from bash shell
#!/bin/bash
set -e # exit on first error
TRANSLATION="kjv"
all_books="
'GEN' => 'Genesis',
'EXO' => 'Exodus',
'LEV' => 'Leviticus',
'NUM' => 'Numbers',
'DEU' => 'Deuteronomy',
'JOS' => 'Joshua',
'JDG' => 'Judges',
'RUT' => 'Ruth',
'1SA' => '1 Samuel',
'2SA' => '2 Samuel',
'1KI' => '1 Kings',
'2KI' => '2 Kings',
'1CH' => '1 Chronicles',
'2CH' => '2 Chronicles',
'EZR' => 'Ezra',
'NEH' => 'Nehemiah',
'EST' => 'Esther',
'JOB' => 'Job',
'PSA' => 'Psalms',
'PRO' => 'Proverbs',
'ECC' => 'Ecclesiastes',
'SNG' => 'Song of Songs',
'ISA' => 'Isaiah',
'JER' => 'Jeremiah',
'LAM' => 'Lamentations',
'EZK' => 'Ezekiel',
'DAN' => 'Daniel',
'HOS' => 'Hosea',
'JOL' => 'Joel',
'AMO' => 'Amos',
'OBA' => 'Obadiah',
'JON' => 'Jonah',
'MIC' => 'Micah',
'NAM' => 'Nahum',
'HAB' => 'Habakkuk',
'ZEP' => 'Zephaniah',
'HAG' => 'Haggai',
'ZEC' => 'Zechariah',
'MAL' => 'Malachi',
'MAT' => 'Matthew',
'MRK' => 'Mark',
'LUK' => 'Luke',
'JHN' => 'John',
'ACT' => 'Acts',
'ROM' => 'Romans',
'1CO' => '1 Corinthians',
'2CO' => '2 Corinthians',
'GAL' => 'Galatians',
'EPH' => 'Ephesians',
'PHP' => 'Philippians',
'COL' => 'Colossians',
'1TH' => '1 Thessalonians',
'2TH' => '2 Thessalonians',
'1TI' => '1 Timothy',
'2TI' => '2 Timothy',
'TIT' => 'Titus',
'PHM' => 'Philemon',
'HEB' => 'Hebrews',
'JAS' => 'James',
'1PE' => '1 Peter',
'2PE' => '2 Peter',
'1JN' => '1 John',
'2JN' => '2 John',
'3JN' => '3 John',
'JUD' => 'Jude',
'REV' => 'Revelation',
"
usage="
verses.sh
-b [required] book name
-r [required] range
-t [optional] translation (default: kjv)
or
list [optional] list all books and their abbreviations for the use in -b option
examples:
1) verses.sh -b john -r 1:29 -t kjv
2) verses.sh -b matthew -r 1:1-20 -t kjv
3) verses.sh list
"
FIRST_ARG="$1"
[ "${FIRST_ARG}" == "list" ] && printf "${all_books}" && exit
while getopts b:r:t:h: flag; do
case "${flag}" in
t)
TRANSLATION=${OPTARG}
;;
r)
RANGE=${OPTARG}
;;
b)
BOOK=${OPTARG}
;;
h)
printf "${usage}"
exit
;;
*)
printf "${usage}"
exit
;;
esac
done
if [ -z "${BOOK}" ] || [ -z "${RANGE}" ]; then
echo "[!] -b and -r options are required. Check again."
printf "${usage}"
exit 1
fi
bible_api_result=$(curl --connect-timeout 10 --max-time 10 -s "https://bible-api.com/${BOOK}+${RANGE}")
chapter_numbers=$(echo "${bible_api_result}" | jq -r '.verses[].chapter')
verse_numbers=$(echo "${bible_api_result}"| jq -r '.verses[].verse')
verse_texts=$(echo "${bible_api_result}"| jq -r '.verses[].text')
chapter_and_verses=$(paste -d ":" <(echo "${chapter_numbers}") <(echo "${verse_numbers}"))
paste -d " " <(echo "${chapter_and_verses}") <(echo "${verse_texts}" | awk NF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment