text2ascii

From S23Wiki

#!/bin/bash
# Convert string to ASCII code
# mutante / s23.org
declare -a INPUT
echo "Enter characters separated by space to be converted to ASCII code. "
read -a INPUT
char_count=${#INPUT[*]}
i=0
while [ $i -lt $char_count ]; do
ASCII=`perl -e 'print ord shift' ${INPUT[$i]}`
CHAR=${INPUT[$i]}
echo -e "$CHAR - $ASCII"
i=$(($i+1))
done

Example:

mutante@cgn:~$ ./text2ascii.sh
Enter characters seperated by space to be converted to ASCII code.
F O O B A R
F - 70
O - 79
O - 79
B - 66
A - 65
R - 82

Can you change this so that input does not have to be separated by spaces anymore? So that FOOBAR would produce the same result. Thanks Mutante 22:52, 1 April 2008 (CEST)

Personal tools