File: coy.sh 1 #!/bin/sh 2 3 # The MIT License (MIT) 4 # 5 # Copyright © 2020-2025 pacman64 6 # 7 # Permission is hereby granted, free of charge, to any person obtaining a copy 8 # of this software and associated documentation files (the “Software”), to deal 9 # in the Software without restriction, including without limitation the rights 10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 # copies of the Software, and to permit persons to whom the Software is 12 # furnished to do so, subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be included in 15 # all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 # SOFTWARE. 24 25 26 # coy [base] 27 # coy [base] [years] 28 # coy [amount] [base] [years] 29 # 30 # Compound Over Years does what it says, by showing a TSV table. It accepts 31 # 1, 2, or 3 arguments for the parameters: the default amount is 1.0, while 32 # the default year-span is 10. 33 34 35 case "$1" in 36 -h|--h|-help|--help) 37 awk '/^# +coy /, /^$/ { gsub(/^# ?/, ""); print }' "$0" 38 exit 0 39 ;; 40 esac 41 42 if [ $# -eq 0 ]; then 43 awk '/^# +coy /, /^$/ { gsub(/^# ?/, ""); print }' "$0" 44 exit 0 45 fi 46 47 awk ' 48 BEGIN { 49 quantity = 1.0 50 base = 1.0 51 years = 10 52 53 switch (ARGC) { 54 case 2: 55 base = ARGV[1] + 0.0 56 break; 57 58 case 3: 59 base = ARGV[1] + 0.0 60 years = ARGV[2] + 0 61 break; 62 63 case 4: 64 quantity = ARGV[1] + 0.0 65 base = ARGV[2] + 0.0 66 years = ARGV[3] + 0 67 break; 68 69 default: 70 msg = "\x1b[31monly 1, 2, or 3 arguments are supported\x1b[0m\n" 71 print msg > "/dev/stderr" 72 exit 1 73 } 74 75 print "year\tquantity" 76 for (k = 1.0; y <= years; y++) { 77 printf "%d\t%.4f\n", y, quantity * k 78 k *= base 79 } 80 exit 81 } 82 ' "$@"