Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
## DAY1=01; DAY7=07
## echo $DAY1
01
## echo $DAY7
07
## grep "SOMETHING" /var/log/node/2019/02/{$DAY1..$DAY7}/messages
grep: /var/log/node/2019/02/{01..07}/messages: No such file or directory
The problem is with the order in which bash does expansions. Brace expansion is performed before parameter expansion, and those literal characters "$DAY1..$DAY7" are not a legitimate brace expression. There is no simple way to do what you want in bash. You need to do one of:
write a loop to generate the set of strings,
use an external command like seq with its --format option, or
perhaps use zsh, where "{$Var1..$Var2}" does what you want here.
But that looks a bit, well, sub-optimal, doesn't it?
Regarding post#1
The "bracket wildcard" is a "character set". Represents one character. So 0[0-7] or 1[0-7] works. But if the range spans over a decade then this method fails.
BTW the character set is really a "wildcard" like * because it is matched against files, and generates what it finds.
In contrast, { } generates a range unconditionally, without matching files.
^ I agree with everything you said.
Actually, I suggested #7 because that's the only solution that came to my mind to satisfy the initial OP's request, namely to define range with variables inside a script...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.