1 |
Grant asks: |
2 |
|
3 |
> >> > cd dir1 |
4 |
> >> > for i in *jpg |
5 |
> >> > do |
6 |
> >> > j = basename $i .jpg |
7 |
> >> > cp -u ${j}.jpg dir2/${j}_original.jpg |
8 |
> >> > done |
9 |
> >> > |
10 |
> >> > 'cp -u' works around the messy problem of checking if the |
11 |
> >> > destination file exists |
12 |
[...] |
13 |
> I put the above script in a file, added the appropriate header, issued |
14 |
> chmod, and when I execute with ./file I get a bunch of these: |
15 |
> |
16 |
> ./script: line 6: j: command not found |
17 |
> cp: cannot stat `.jpg': No such file or directory |
18 |
|
19 |
This: |
20 |
j = basename $i .jpg |
21 |
should be more like this: |
22 |
j=$( basename $i .jpg ) |
23 |
|
24 |
Or: j=${i%.jpg} |
25 |
|
26 |
That is, there must be no whitespace around the '='. And in order to set j |
27 |
to the result of a command, use $( command ) or ` command `. |
28 |
|
29 |
Wonko |
30 |
-- |
31 |
gentoo-user@l.g.o mailing list |