Note that there are some explanatory texts on larger screens.

plurals
  1. POBash Script Leet Text Convertor: How to get array to recognize spaces
    text
    copied!<p>The issue with the code below is that I can not seem to get the array to recognize when the text has spaces in it or not. I figured adding the ' ' value in the array would handle this, but I was wrong. I haven't found much luck from searches about how to get an array to recognize spaces in bash scripting.</p> <pre><code>#!/bin/bash if [ "$1" == "-e" ]; then # if the cli argument is -e OPT="encrypt"; # set the option to encrypt elif [ "$1" == "-d" ]; then # if the cli argument is -d OPT="decrypt"; # set the option to decrypt else # else show the proper usage echo "Usage - Encrypt text: ./l33t.sh -e text"; echo "Usage - Decrypt text: ./l33t.sh -d text"; exit; fi #creating an array for leet text and plain text declare -a LEET=('ɐ' 'ß' '©' 'Ð' '€' 'ƒ' '&amp;' '#' 'I' '¿' 'X' '£' 'M' '?' 'ø' 'p' 'O' 'Я' '§' '†' 'µ' '^' 'W' '×' '¥' 'z' '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' ' '); declare -a ENG=('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' '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' ' '); echo -n "Please enter a string to $OPT: "; # asking for user input read INPUT; # grab the input while read letter; # for each character in the input (check the grep near done) do for i in {0..37} # for each item in the array do if [ "$OPT" == "encrypt" ]; then # if the option is set to encrypt FIND=${ENG[$i]}; # the array to look through is the plain array elif [ "$OPT" == "decrypt" ]; then # else the array to look through is the leet text array FIND=${LEET[$i]}; fi if [ "$OPT" == "encrypt" ]; then # if the option is set to encrypt if [ "$FIND" == "$letter" ]; then # if our character is in the plain array ENCRYPTED+=${LEET[$i]}; # Add to Encrypted that values leet transformation fi elif [ "$OPT" == "decrypt" ]; then # else do the same thing except with oposite arrays if [ "$FIND" == "$letter" ]; then ENCRYPTED+=${ENG[$i]}; fi fi done done &lt; &lt;(grep -o . &lt;&lt;&lt; $INPUT) echo $ENCRYPTED; # echo the result </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload