X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/1cbe13ec167148c76df5030a1a35a7ed6df78a67..cdf058f49da79511145631f9c64e635dce7852a7:/unitproc/bktemp-validateInput?ds=sidebyside diff --git a/unitproc/bktemp-validateInput b/unitproc/bktemp-validateInput index 2fa7082..e1678f1 100644 --- a/unitproc/bktemp-validateInput +++ b/unitproc/bktemp-validateInput @@ -7,19 +7,21 @@ try() { "$@" || die "cannot $*"; } #o validateInput() { # Desc: Validates Input # Usage: validateInput [str input] [str input type] - # Version: 0.3.0 + # Version: 0.3.1 # Input: arg1: string to validate # arg2: string specifying input type (ex:"ssh_pubkey") # Output: return code 0: if input string matched specified string type - # Depends: bash 5, yell + # Depends: bash 5, yell() + + local fn argInput argType # Save function name - local FN="${FUNCNAME[0]}"; + fn="${FUNCNAME[0]}"; # Process arguments argInput="$1"; argType="$2"; - if [[ $# -gt 2 ]]; then yell "ERROR:$0:$FN:Too many arguments."; exit 1; fi; + if [[ $# -gt 2 ]]; then yell "ERROR:$0:$fn:Too many arguments."; exit 1; fi; # Check for blank if [[ -z "$argInput" ]]; then return 1; fi @@ -60,37 +62,37 @@ validateInput() { #==BEGIN sample code== testKey="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCq8G0XWi8A+MXNu7MEaxDsZJUwtgPC4shGAAarXC4PQTRxLfUHtyWkNbzGh31U/bKI3Snp1O78yOVEZSjdmWkDvkwtWKJQcoZBStgqw9oIPE0oG8uh49XoX77nVabi0JCf8zO63Ai4/9EdwyqE9xsJ+soOYt2V5+UCj0zsv1xpt2YhfYyXrzBv9x6k9lCxy0NW3Ik1mSW+OzSOT3tgDf36ujV/CI2i8ERM9civWy8FtFOReZMV2kkbj7fXI4E1wKM1RFIn7er1MseCSvbvh3o2uCO46/euqHAstYs5cL+4yB2qM/xKfHT5aocDjq7GBLKtree9xdNF0EE9CNr/+J5R"; keyType="ssh_pubkey"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; testKey="blah-blah onetwothreeREEE"; keyType="ssh_pubkey"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; -testKey3=""; +testKey=""; keyType="ssh_pubkey"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; testKey="age1c3s6huz6en6jh40cem0erc0m2un2ry85my0t0ujj4a5cu8gzkysq9l39e4"; keyType="age_pubkey"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; testKey="123" keyType="integer"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; testKey="123abc" keyType="integer"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; testKey="year" keyType="time_element"; -if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "Doesn't look like a valid $keyType:\"$testKey\""; fi echo ""; #==END sample code==