Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-26-2009, 01:50 PM
|
#1
|
|
Member
Registered: Aug 2007
Location: Sweden
Distribution: OS X, Gentoo, FreeBSD
Posts: 82
Rep:
|
Brace expansion: does this kind exist?
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. 
|
|
|
|
04-26-2009, 04:16 PM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
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.
Cheers,
Tink
|
|
|
|
04-26-2009, 04:36 PM
|
#3
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
|
04-26-2009, 04:43 PM
|
#4
|
|
Member
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 324
Rep: 
|
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
|
|
|
|
04-28-2009, 03:45 AM
|
#5
|
|
Member
Registered: Aug 2007
Location: Sweden
Distribution: OS X, Gentoo, FreeBSD
Posts: 82
Original Poster
Rep:
|
Quote:
Originally Posted by Tinkster
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
|
Thanks 
Ugly, but it works!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:43 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|