Bash: for…in-loop fails, what am I doing wrong?

Paul Smith paul at mad-scientist.net
Thu Jan 10 21:03:40 UTC 2013


On Thu, 2013-01-10 at 20:49 +0000, Tony Arnold wrote:
> Or you could use the -exec option to the find command as follows:
> 
> find -regextype posix-extended \
>      -regex '.*/P[A-Z0-9][0-9]{6}\.(jpg|JPG|jpeg)' \
>      -exec date --reference="{}" '+%Y%m' \;

Unfortunately this doesn't address the rest of the OP's loop, which was:

>     # More things to happen here, but this is only a test.

-exec can only invoke a single command hence cannot replace the OP's
loop, by itself.

> What follows -exec is executed once for each file found. The {} is
> replaced with the file name. Note the command must be terminated by an
> escaped semi-colon, i.e., \;

If you read the rest of my response I did suggest basically the same
thing (write a script and invoke it with find -exec).

If you have a lot of these kinds of things to do, however, writing
scripts to handle each situation can get very annoying.





More information about the ubuntu-users mailing list