Gentoo Archives: gentoo-user

From: Grant <emailgrant@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Quick script request
Date: Wed, 25 Jun 2008 17:16:44
Message-Id: 49bf44f10806251016w36d80585n1ff1813d8e0d08d1@mail.gmail.com
In Reply to: Re: [gentoo-user] Quick script request by Alan McKinnon
1 >> >> Feel free to ignore me here, but if anyone could whip out a quick
2 >> >> script for this I would really appreciate it.
3 >> >>
4 >> >> I need to move any files from dir1 to dir2 if they don't already
5 >> >> exist in dir2 with a slightly different filename. The dir1 files
6 >> >> are named like a-1.jpg and the dir2 files are named like
7 >> >> a-1_original.jpg.
8 >> >>
9 >> >> - Grant
10 >> >
11 >> > rough and ready, off the top of my head:
12 >> >
13 >> > cd dir1
14 >> > for i in *jpg
15 >> > do
16 >> > j = basename $i .jpg
17 >> > cp -u ${j}.jpg dir2/${j}_original.jpg
18 >> > done
19 >> >
20 >> > 'cp -u' works around the messy problem of checking if the
21 >> > destination file exists
22 >>
23 >> Thanks guys, can you tell me how to execute this? Put it in a file
24 >
25 > yes
26 >
27 >> and './file' I think?
28 >
29 > Either that or chmod a+x file and execute it directly
30 >
31 >> Should I have special stuff at the top of the
32 >> file?
33 >
34 > #!/bin/bash
35
36 I put the above script in a file, added the appropriate header, issued
37 chmod, and when I execute with ./file I get a bunch of these:
38
39 ./script: line 6: j: command not found
40 cp: cannot stat `.jpg': No such file or directory
41
42 - Grant
43 --
44 gentoo-user@l.g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Quick script request Alex Schuster <wonko@×××××××××.org>