Numerology With Bash Code Example
Page 1 of 1
Numerology With Bash Code Example
- Code:
#!/bin/bash
# Usage ./num.sh "test"
# (c) J~Net 2016
# jnet.forumotion.com/t1330-numerology-with-bash-code-example#1860
ptr=1
if [ -z "$1" ] ; then
echo -n "Word or phrase: "
read basis
else
basis="$@"
fi
echo "$basis" > out.txt
basis="$( echo $basis | \
tr '[A-Z]' '[a-z]' | \
tr -Cd '[:alnum:]' )"
basislength="$( echo $basis | wc -c )"
echo "(Working with $basis which has \
$basislength characters)"
while [ $ptr -lt $basislength ] ; do
letter="$( echo $basis | cut -c $ptr )"
ordvalue="$(echo $letter | \
perl -e '$a=getc(); print ord($a)-96' )"
echo "letter $letter has value $ordvalue" >> out.txt
ptr="$(( $ptr + 1 ))"
done
# ā€ˇfilter out non numbers
cat out.txt | sed 's/[^0-9]*//g' > nout.txt
# Sum all numbers together
SUM=0; for i in `cat nout.txt`;
do SUM=$(($SUM + $i));
done;
echo "Your Words "
cat out.txt
echo "Adds up to a total of "
echo $SUM
rm nout.txt; rm out.txt
exit 0
Last edited by jamied_uk on 23rd July 2016, 16:18; edited 1 time in total
Similar topics
» ROT13 In Bash On Linux Code Cipher Example
» A simple bash fruit machine game code example
» Using Sed bash Script On Linux To Generate Morse Code Without Sound
» Numerology Calculator
» php code website base full of open source code
» A simple bash fruit machine game code example
» Using Sed bash Script On Linux To Generate Morse Code Without Sound
» Numerology Calculator
» php code website base full of open source code
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum