Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.42 KB | None | 0 0
  1. #!/bin/bash
  2. # ----------------------------------------------------------------------------
  3. # Conversor de código morse.
  4. #
  5. # Uso: zzmorse [string]
  6. # Ex.: zzaleatorio alfredo
  7. #      zzaleatorio ... --- ...
  8. #
  9. # Autor: Alfredo Casanova <atcasanova (a) gmail com>
  10. # Desde: 2018-04-26
  11. # Versão: 1
  12. # Licença: GPL
  13. # ----------------------------------------------------------------------------
  14.  
  15.  
  16. zzmorse(){
  17.     match_pattern="^[ \.\-]+$"
  18.     [[ $* =~ $match_pattern ]] && input=morse || input=text
  19.  
  20.     if [[ "$input" == "morse" ]]; then
  21.         declare -A morse=( [.-]=A  [-...]=B  [-.-.]=C  [-..]=D  [.]=E  [..-.]=F  [--.]=G  [....]=H  [..]=I  [.---]=J  [-.-]=K  [.-..]=L  [--]=M  [-.]=N  [---]=O  [.--.]=P  [--.-]=Q  [.-.]=R  [...]=S  [-]=T  [..-]=U  [...-]=V  [.--]=W  [-..-]=X  [-.--]=Y  [--..]=Z  [-----]=0  [.----]=1  [..---]=2  [...--]=3  [....-]=4  [.....]=5  [-....]=6  [--...]=7  [---..]=8  [----.]=9 )
  22.         for i in $*; do
  23.             echo -n "${morse[$i]}"
  24.         done
  25.         echo
  26.     else
  27.         declare -A tomorse=( [A]=.- [B]=-... [C]=-.-. [D]=-.. [E]=. [F]=..-. [G]=--. [H]=.... [I]=.. [J]=.--- [K]=-.- [L]=.-.. [M]=-- [N]=-. [O]=--- [P]=.--. [Q]=--.- [R]=.-. [S]=... [T]=- [U]=..- [V]=...- [W]=.-- [X]=-..- [Y]=-.-- [Z]=--.. [0]=----- [1]=.---- [2]=..--- [3]=...-- [4]=....- [5]=..... [6]=-.... [7]=--... [8]=---.. [9]=----. )
  28.         texto="$*"
  29.         for (( i=0; i<${#texto}; i++ )); do
  30.             char=${texto:$i:1}
  31.             echo -n "${tomorse[${char^^}]} ";
  32.         done
  33.         echo
  34.     fi
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement