Gentoo Archives: gentoo-user

From: Drew Tomlinson <drew@××××××××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Simple command line stuff
Date: Tue, 11 Oct 2005 07:29:54
Message-Id: 434B68EB.6000903@mykitchentable.net
In Reply to: Re: [gentoo-user] Simple command line stuff by Mark Knecht
1 Mark Knecht wrote:
2
3 >On 10/10/05, Spider (D.m.D. Lj.) <spider@g.o> wrote:
4 >
5 >
6 >>On Sun, 2005-10-09 at 19:06 -0700, Mark Knecht wrote:
7 >>
8 >>
9 >>>Hi,
10 >>> I don't have a single book on Linux. (Amazing...) Can someone
11 >>>recommend a simple book on command line stuff, or better yet a good
12 >>>web site on this topic?
13 >>>
14 >>> For instance, I wanted to run a specific command on every file in a
15 >>>directory which will create a new file, so I need to do
16 >>>
17 >>>command file1.wav file1-convert.wav
18 >>>
19 >>>I need to take each name, create a new name to build the actual
20 >>>command that gets run and then do that for every file in the
21 >>>directory, or even in a hierarchy of directories.
22 >>>
23 >>>Thanks,
24 >>>Mark
25 >>>
26 >>>
27 >>
28 >>For bash / zsh and other advanced(?-) shells:
29 >>
30 >>for f in *.wav; do command "$f" "${f/.wav/-convert.wav}";done
31 >>
32 >>The " " are there to prevent files with spaces in them (evil!) from
33 >>becoming too annoying and appearing as multiple commandline arguments.
34 >>
35 >>
36 >>//Spider
37 >>
38 >>
39 >>
40 >
41 >Thanks to all for the great answers and pointers. I appreciate it very much.
42 >
43 >Cheers,
44 >Mark
45 >
46 >
47
48 And just one more point. The "for" loop is shell dependent and works in
49 sh and its cousins. But if you're using a csh based shell, it's
50 "foreach". Now I'm not commenting on what shells are better than others
51 but just wanted to make the point for anyone who might follow this
52 thread in the future.
53
54 Oh, and another thought. The "find" command can do this for you as
55 well, IIRC.
56
57 Cheers,
58
59 Drew
60 --
61 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Simple command line stuff "Spider (D.m.D. Lj.)" <spider@g.o>