I wrote this script to encode / encrypt data from a sql query by changing the names of tables and fields (I played on the ASCII character codes).

#! /bin/bash

chr() {
  [ "$1" -lt 256 ] || return 1
  printf "\\$(printf '%03o' "$1")"

ord() {
  LC_CTYPE=C printf '%d' "'$1"

read -p "saisir votre requete: "  req
printf "%s\n" "$req" > t1.txt

sed -e 's/[;,()'\'']/ /g;s/  */ /g' t1.txt > t.txt

while read line; do 
   for word in "${line[@]}"; do 
    if ! [[ "$word" =~ $(echo ^\($(paste -sd'|' ./req.txt)\)$) ]]; then
     for i in $(seq 1 ${#str}); do
     car=$(echo $(echo $str | cut -c$i))
      x=$(ord "$car")
     let "x= (((x/2) * 3) + 1)"
     var=$(chr "$x")
     echo $str  |  sed "s/\$car/\$var/g"
     sed -i -e "s/$word/$str/g" t1.txt 


done < t1.txt

the file req.txt contains words like each request as select, insert, update ....

I executed the script but the terminal hangs and displays each word according to the number of characters:

Expl: from was dislayed 4 time

closed as unclear what you're asking by Braiam, Michael Homer, Networker, Karlson, Archemar Apr 13 '15 at 16:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • while read -a line; do – Costas Apr 13 '15 at 8:11
  • A typo in function ord()? you have an extra quote preceding $1 – apaul Apr 13 '15 at 8:16
  • @apaul No, it produce ascii No. of symbol in $1 variable – Costas Apr 13 '15 at 8:18
  • @Costas Yes, my mistake, I thought I read "'$1" – apaul Apr 13 '15 at 8:34
  • What error is printed? – Lambert Apr 13 '15 at 8:50

If you want the output value of a command or function to be assigned use this syntax:

 x=$(ord "$car")
 var=$(chr "$x")

(The errors you've got because the syntax you used, e.g. x=ord $car, will do the following: the variable x will get assigned the string "ord", and the variable x then made available to the environment of the subsequent command $car; but the expanded $car is not a command, so you get errors that "s", "0", etc. are not recognized as commands.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.