Bash: How to increment an alphabetic value of a variable alphabetically?
So for numbers it's easy.
Code:
PAGE=1; ((PAGE++)); echo $PAGE What about this? Code:
LETTER=A; ????; echo $LETTER jdk |
use perl ;)
Code:
perl -e '$x=A;print $x++, "=", $x,"\n"' |
If you want to do it in a loop try:
Code:
for letter in {A..Z} ; do |
Code:
function NextLetter () { |
Thanks for your efforts. Not really what I want. I have a bash script here:
Code:
#!/bin/bash Code:
http://www.xxx.xxx/languages-pronunc...lphabetically/L/page-1 The pages are also organised by the initial letter of the word shown in bold above. So in the example above I would want to increment the "L" to "M" when all the words in "L" have been exhausted. I hope that's clearer. jdk |
Quote:
You asked how to go from letter to letter, you've been given that, any of those techniques could be used as an "outer loop" to go through letters with your inner loop doing the page stealing. |
Quote:
jdk |
With a suitable replacement for LEFT, this should do what you want.
Code:
#!/bin/bash Here is the same loop modified to only echo URL and fetch 3 pages for each letter to test it. Code:
LEFT="http://www.xxx.xxx/languages-pronunciations/de/alphabetically/" |
So with the information already in this thread and two lines added to your script to handle going from L to N, as I couldn't be bothered downloading more because 3 letters is enough to prove my letter incrementing works (and with a line to only download 10 pages max) I can download the following files:
Code:
-rwxr-xr-x 1 jdkaye jdkaye 376 Dec 18 21:16 dumbass.sh Quote:
So yeah, I kinda get what you expect. |
Quote:
Awww, you wrote it for him, how generous :) :) Personally I used Code:
for LETTER in {A..Z} ; do |
Quote:
jdkaye has been here long enough to deserve that much respect. Quote:
|
Thank you all very much.
(1) I wanted to use bash because beyond very simple bash scripts (I've written loads) I haven't done much bash writing. (2) My real question was, "Does an alphabetic function exist in bash. I did not ask for nor did I expect anyone to write it for me in the event that such a function is not built into bash. I downloaded the bash manual (4.2) and did a thorough search of that manual before bothering members of this august group. I could find the numeric increment function (shown in an earlier post) and happily used it. I thought perhaps an alphabetic increment function did exist but I was too thick to find it in the manual so I asked here. (3) I am fully aware that one can write a function doing that job but that is not what my question was and not what I expected. A simple "no, but you can write one yourself" would have sufficed. (4) As for using Perl, one of the points of my task was teaching myself more about bash. If I wanted to do the same thing using another language I would have chosen Icon which is the language I'm most familiar with. (5) Finally, I think I'll explore the unicode or ascii route. Now, I'll see if there's a bash function that converts octals/hexadecimals numbers to decimals and vice versa. But don't worry; I won't ask. I wouldn't want you to think I'm asking you to write my code for me. Thank you all once again. jdk |
Focusing on post #5 I thought that your ultimate goal was to automate the download, not just to find a built-in alpha-increment feature of bash.
I did not immediately know how to best do that so thought I would learn by doing it - and I gained something by that. I did not consider it as writing your script for you, or that you had not "done enough" on your own - who am I to make such a judgment anyway?! My own intent was only to be helpful. Sorry if it was taken any other way, definitely not intended. Best of luck in your explorations! |
Quote:
Quote:
Quote:
I just happened to have spent the last few days tidying up other peoples bash scripts including dealing with alphabet loops and date loops. |
Quote:
But, forcing shell for tasks it's not easy to do is just giving yourself a headache is it not? |
All times are GMT -5. The time now is 09:03 AM. |