bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash, Sed and Find


From: Francis Montagnac
Subject: Re: Bash, Sed and Find
Date: 5 Apr 2001 18:12:46 GMT

In article <slrn9cp18f.ub9.matt@flop.localnet>,
 matt@cipherdesign.com (Matt Venn) writes:
...
>1/- cd /tmp; mkdir new; touch new/1
>2/- find new/ -type f \
>-exec echo $( echo {} | sed -e 's#\(.*\)#sed->\1<#' ) \;
>3/- find new/ -type f -exec echo $( echo {} | sed -e 's#new/##' ) \;
>4/- echo "new/1" | sed -e 's#new/##'

>Description:
>1/- moves to /tmp, creates /tmp/new/1
>2/- shows that sed is getting the whole path of new/1 - prints
>'sed->new/1<'

In fact not: it gets literally {}, then find gets: -exec echo 'sed->{}'
and expand {} to new/1, then echo is called (by find).
...
>One thing in particular that I don't understand is that I thought $()
>was evaluated before the rest of the command. 

Yes you're right.

>If this is the case, how does the {} inside the $() get interpolated?

It doesn't.

With -exec, using an auxiliary command called with {} is safer.

Personally, I would try to not use -exec but something like 

        find ...|xargs sed -e '...'

The -printf option of the gnu find, if you have it, may help as well.

-- 
Francis.Montagnac@sophia.inria.fr, Tel: (33)04 92 38 79 11
INRIA Sophia, 2004, rte des Lucioles, B.P.93 - 06902 Sophia Antipolis Cedex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]