For example 2211 needs to display 6 but I can’t find a command that helps me with it.
I have already tried with cut but that can only cut one at a time.
For example 2211 needs to display 6 but I can’t find a command that helps me with it.
I have already tried with cut but that can only cut one at a time.
5
Answers
Works in Debian. Try this:
Using a
while
+read
loop.If your bash is new enough, instead of
declare
If you have
bash
version 5.2 (the most recent version to this date):Math variant probably there are more elegant variants
Another (Shellcheck-clean) way to do it with arithmetic instead of string manipulation: