LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 09-15-2008, 01:06 PM   #1
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Rep: Reputation: 15
Angry 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 ??
 
Old 09-15-2008, 01:16 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

Quote:
Originally Posted by lipun4u View Post
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
 
Old 09-15-2008, 07:43 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
touch test{10..100}
 
Old 09-15-2008, 09:47 PM   #4
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Original Poster
Rep: Reputation: 15
can anyone gv me a good link about this (i think this is known as shell expansion) ???
 
Old 09-15-2008, 09:59 PM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by lipun4u View Post
can anyone gv me a good link about this (i think this is known as shell expansion) ???
check my sig, learn bash link
 
Old 09-16-2008, 02:29 PM   #6
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

Quote:
Originally Posted by ghostdog74 View Post
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
 
Old 09-16-2008, 02:38 PM   #7
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
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.
 
Old 09-16-2008, 02:54 PM   #8
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
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.
 
Old 09-16-2008, 03:30 PM   #9
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Quote:
Originally Posted by jan61 View Post
[...]
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
)
 
Old 09-16-2008, 03:39 PM   #10
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
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
 
Old 09-16-2008, 03:41 PM   #11
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Quote:
Originally Posted by Kenhelm View Post
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
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] group permissions: touch: cannot touch `filename': Permission denied bartonski Linux - General 2 11-27-2008 09:23 AM
how to put an alphabet in seq command silverhand Programming 3 10-05-2007 02:57 PM
Error - can't touch touch: /var/lock - filesystem problem? xanas3712 Linux - Newbie 0 05-10-2004 05:26 AM
snd-seq-oss problem CuteAndFluffy Linux - Hardware 1 01-16-2003 10:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration