Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
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.
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.
|
 |
09-15-2008, 01:06 PM
|
#1
|
Member
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118
Rep:
|
touch test{seq 10 10 1000)}
I want to use seq command inside shell expansion..like this
touch test{seq 10 10 1000)}
is it possible ??
|
|
|
09-15-2008, 01:16 PM
|
#2
|
Member
Registered: Jun 2008
Posts: 235
Rep:
|
Moin,
Quote:
Originally Posted by lipun4u
I want to use seq command inside shell expansion..like this
touch test{seq 10 10 1000)}
|
Did you try it? It can't work. You want to create files with the names test10, test20, ...? One way is:
Code:
touch $(seq 10 10 1000 | sed 's/^/test/')
Jan
|
|
|
09-15-2008, 07:43 PM
|
#3
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
Code:
touch test{10..100}
|
|
|
09-15-2008, 09:47 PM
|
#4
|
Member
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118
Original Poster
Rep:
|
can anyone gv me a good link about this (i think this is known as shell expansion) ???
|
|
|
09-15-2008, 09:59 PM
|
#5
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
Quote:
Originally Posted by lipun4u
can anyone gv me a good link about this (i think this is known as shell expansion) ???
|
check my sig, learn bash link
|
|
|
09-16-2008, 02:29 PM
|
#6
|
Member
Registered: Jun 2008
Posts: 235
Rep:
|
Moin,
Quote:
Originally Posted by ghostdog74
Code:
touch test{10..100}
|
uhm:
Code:
jan@jack:~/tmp> touch test{10..100}
jan@jack:~/tmp> ls -l test*
-rw-r--r-- 1 jan users 0 2008-09-16 21:27 test{10..100}
???
Jan
|
|
|
09-16-2008, 02:38 PM
|
#7
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
If I recall correctly It's a version 3.0 feature, as far as bash is concerned (available in Korn Shell 93 and Z-Shell too).
Last edited by radoulov; 09-16-2008 at 02:41 PM.
|
|
|
09-16-2008, 02:54 PM
|
#8
|
Member
Registered: Jun 2008
Posts: 235
Rep:
|
Moin,
that could be an explanation ;-):
Code:
jan@jack:~/tmp> bash --version
bash --version
GNU bash, version 2.05b.0(1)-release (i586-suse-linux)
Copyright (C) 2002 Free Software Foundation, Inc.
I should upgrade my machine some day ...
Jan
EDIT: But as far as I understand, this will not create files with step 10 numbers from 10 to 1,000 as requested, isn't it? Could this be done in v3.0?
Last edited by jan61; 09-16-2008 at 02:57 PM.
|
|
|
09-16-2008, 03:30 PM
|
#9
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
Quote:
Originally Posted by jan61
[...]
EDIT: But as far as I understand, this will not create files with step 10 numbers from 10 to 1,000 as requested, isn't it? Could this be done in v3.0?
|
If you want to do it in bash without external commands,
you could use something like this:
Code:
touch $(
for i in {1..1000}; do
((i%10))||printf "test%d\n" $i
done
)
|
|
|
09-16-2008, 03:39 PM
|
#10
|
Member
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360
Rep: 
|
This creates test10 test20 test30 .......... test990 test1000
Code:
touch test{1..100}0
There are some other examples at
http://www.linuxjournal.com/content/...race-expansion
|
|
|
09-16-2008, 03:41 PM
|
#11
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
Quote:
Originally Posted by Kenhelm
|
 Nice one!
If your shell does not support brace expansion and you have GNU seq (read never  ):
Code:
touch $(seq -f"test%g" 10 10 1000)
Last edited by radoulov; 09-16-2008 at 03:52 PM.
|
|
|
All times are GMT -5. The time now is 01:06 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
|
|