简体   繁体   中英

How to specify range using bases greater than 10 in MacOS Terminal

I am using

curl -0 https://cdn.(website).com/[range].(extension) -o "#1.(extension)"

to download files in a range of filename values.

How can I specify the range in a base higher than base 10 (I'm aiming for base 36 to encompass 0-9, az)? ex. [000-zzz]

I don't know of an easy way to print numbers in a nonstandard base in bash, but you could use bash's brace expansion to generate the range textually. You can nest brace expansions, so {{0..9},{a..z}} will give you the digits followed by the lowercase letters. Then stack three of those to get all three-item sequences.

Note that this is a different feature from curl 's bracket and brace expansion, so you can't use it in the output filename (the #1 in your example). But you can make a shell for loop, and use the shell variable to create the output filename. Something like this:

for itemnum in {{0..9},{a..z}}{{0..9},{a..z}}{{0..9},{a..z}}; do
    curl -0 https://cdn.(website).com/${itemnum}.(extension) -o "${itemnum}.(extension)"
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM