Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Shell brace expansion is wonderful, but I've ran in to a snag a bunch of times now. The last time was when I wanted to mount two disks - mounted at /storage/1 and /storage/2, respectively. So, to save time, I did "mount /storage/{1,2}" which of course doesn't work, since it expands to "mount /storage/1 /storage/2", and /storage/1 is a directory, not a block device as it'd have to be in this case. What I'd like is for it to break it up into multiple commands, something like
mount /storage/{{1,2}} == for P in 1 2; do mount /storage/$P; done
or
echo {{1..100}} == for i in {1..100}; do echo $i; done
I'm pretty sure this isn't possible without patching your shell (at least bash). Please prove me wrong.
No, you're right. And it (the patch) would have to be pretty clever to know what
to do for which commands ... that, or you'd have to introduce a new syntax.
No, you're right. And it (the patch) would have to be pretty clever to know what
to do for which commands ... that, or you'd have to introduce a new syntax.
Tink
Well, I did introduce a new syntax in my post - double braces (lack of imagination? Who knows, but it doesn't really matter).
Quote:
Originally Posted by jschiwal
Something like this is better done using a short script or function that you can do later.
You could write a function that that calls mount for each argument. The arguments could be the result of brace expansion.
This was just an example. It could also be for completely different tasks that also require one argument per invocation, so one script per deal would be pretty useless - it'd be a bit like arguing that you can use seq and xargs instead of brace expansion. Both works, but the latter is a lot prettier.
Quote:
Originally Posted by Kenhelm
You need to escape the space after the command and add an escaped ';' at the end.
Then 'eval' can be used to do a double expansion on the expression.
Code:
eval mount\ /storage/{1,2}\;
mount: can't find /storage/1 in /etc/fstab or /etc/mtab
mount: can't find /storage/2 in /etc/fstab or /etc/mtab
eval echo\ {1..5}\;
1
2
3
4
5
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.