Shell subtract one alphabet letter from current letter

Multi tool use
Multi tool use


Shell subtract one alphabet letter from current letter



I have a file called "current_letter.txt" which displays today's letter (A-K)


cat current_letter.txt
C



Each day the letter increments by one letter (Yesterday's letter would have been "B" Tomorrow's letter will be "D"



How can I put yesterdays letter into a variable?


Example:
A=K
B=A
C=B
D=C
E=D
F=E
G=F
H=G
I=H
J=I
K=J



I'm trying to put yesterday's letter into a variable like


yesterdays_letter=`cat current_letter.txt - 1`



So it uses a - k then repeats itself




2 Answers
2



You can use tr for all your Caesar cipher needs:


tr


#!/bin/bash
for c in {A..Z}
do
b=$(printf '%s' "$c" | tr 'B-ZA' 'A-Z')
echo "One letter before $c is $b"
done



This outputs:


One letter before A is Z
One letter before B is A
One letter before C is B
One letter before D is C
(etc)



The example section you give makes no sense, is that a file's content?



here is the solution:


a='ABCDEFGHIJK';
v=$(cat current_letter.txt);
if [ "$v" = 'A' ]; then
var='K';
else
var=${a[$(($(expr index $a $v)-2))]};
fi;
echo $var;





Hi @ddwolf No the example section means if I "cat current_letter.txt" and the output is "B" i want the variable to be "A" or if "cat current_letter.txt" and the output is "A" I want the variable to be "K" so the example section just represents what i want the letter to be
– John Smith
Jul 3 at 1:20






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

TIDSbhNS2OQ ycdVKsZ7D,J04uCji9oX
MyA ROkfb6O89Hs ch4mRHQgA8 R7Oa gFMx21vyeTalAB

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications