Last active
June 22, 2024 19:10
-
-
Save vtmx/8beb88b4dcea1104f56b68be31979798 to your computer and use it in GitHub Desktop.
dna.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| nucleos=(A C T G) | |
| print_example() { | |
| echo ' ex: ./dna.sh ACTG' | |
| } | |
| main() { | |
| local argv | |
| [[ $2 ]] && { echo 'dna: accept only one argument'; print_example; exit 0; } | |
| [[ $1 ]] && argv=$1 || read -p 'nucleo: ' argv | |
| [[ ${#1} -ne ${#nucleos[@]} ]] && { echo 'dna: accept only four chars'; print_example; exit 1; } | |
| argv=${argv^^} | |
| for ((char = 0; char < ${#argv}; char++)); do | |
| for nucleo in ${nucleos[@]}; do | |
| [[ ${argv:char:1} =~ $nucleo ]] && ((++nnucleos)) | |
| done | |
| done | |
| [[ $nnucleos -eq ${#nucleos[@]} ]] && { | |
| echo ${argv} - Ok | |
| } || { echo 'dna: need four chars valid'; print_example; exit 1; } | |
| } | |
| main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment