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

Tony Arnold tony.arnold at manchester.ac.uk
Thu Jan 10 20:49:06 UTC 2013


Johnny,

On 10/01/13 20:07, Paul Smith wrote:

> Something that will be more reliable than the above would be:
> 
>   find -regextype posix-extended -regex '.*/P[A-Z0-9][0-9]{6}\.(jpg|JPG|jpeg)' \
>       | while IFS= read -r File; do
>           date --reference="${File}" '+%Y%m'
>         done

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' \;

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., \;

Regards,
Tony.
-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 705 344 3082
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk




More information about the ubuntu-users mailing list