From: lbrtchx on
I have some script to find files that works just fine and looks like this:
~
#!/bin/bash

# FIND SEARCH DIRECTORY
_FND_DIR=/

# EXCLUDING
_XKLD=""

find ${_FND_DIR} -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune -o -type f -printf '%T@,%A@,%C@,"%P"\n' > found.txt
~
I would like for the whole discriminating section:
~
-noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune
~
to be included in a parameter like this:
~
_XKLD="-noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune"
~
so that the previou statement looks like:
~
find ${_FND_DIR} ${_XKLD} -o -type f -printf '%T@,%A@,%C@,"%P"\n' > found.txt
~
I have searched for a similar example and tried a number of things and none of them worked.
~
how do you do that?
~
Thanks
lbrtchx

From: Ed Morton on
On 2/3/2010 5:30 AM, lbrtchx(a)gmail.com wrote:
> I have some script to find files that works just fine and looks like this:
> ~
> #!/bin/bash
>
> # FIND SEARCH DIRECTORY
> _FND_DIR=/
>
> # EXCLUDING
> _XKLD=""
>
> find ${_FND_DIR} -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune -o -type f -printf '%T@,%A@,%C@,"%P"\n'> found.txt
> ~
> I would like for the whole discriminating section:
> ~
> -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune
> ~
> to be included in a parameter like this:
> ~
> _XKLD="-noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune"
> ~
> so that the previou statement looks like:
> ~
> find ${_FND_DIR} ${_XKLD} -o -type f -printf '%T@,%A@,%C@,"%P"\n'> found.txt
> ~
> I have searched for a similar example and tried a number of things and none of them worked.
> ~
> how do you do that?
> ~
> Thanks
> lbrtchx
>

man eval:

$ find . -name tmp -print
../tmp
$ x='-name tmp'
$ find . "$x" -print
find: unknown predicate `-name tmp'
$ eval find . "$x" -print
../tmp

Regards,

Ed.
From: Albretch Mueller on
On Feb 3, 2:19 pm, Ed Morton <mortons...(a)gmail.com> wrote:
> On 2/3/2010 5:30 AM, lbrt...(a)gmail.com wrote:
>
>
>
> >   I have some script to find files that works just fine and looks like this:
> > ~
> > #!/bin/bash
>
> > # FIND SEARCH DIRECTORY
> > _FND_DIR=/
>
> > # EXCLUDING
> > _XKLD=""
>
> > find ${_FND_DIR} -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune -o -type f -printf '%T@,%A@,%C@,"%P"\n'>  found.txt
> > ~
> >   I would like for the whole discriminating section:
> > ~
> >   -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune
> > ~
> >   to be included in a parameter like this:
> > ~
> >   _XKLD="-noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune"
> > ~
> >   so that the previou statement looks like:
> > ~
> > find ${_FND_DIR} ${_XKLD} -o -type f -printf '%T@,%A@,%C@,"%P"\n'>  found.txt
> > ~
> >   I have searched for a similar example and tried a number of things and none of them worked.
> > ~
> >   how do you do that?
> > ~
> >   Thanks
> >   lbrtchx
>
> man eval:
>
> $ find . -name tmp -print
> ./tmp
> $ x='-name tmp'
> $ find . "$x" -print
> find: unknown predicate `-name tmp'
> $ eval find . "$x" -print
> ./tmp
>
> Regards,
>
>     Ed.

eval did what I needed but created another (new) problem: if you try
my code you will see eval somehow gets in the way of the "\n" at the
end working, so it is not producing lines but just a very long one
liner

How can I produce actual lines for each entry using eval?

Thanks
lbrtchx


From: Ed Morton on
On 2/3/2010 9:29 PM, Albretch Mueller wrote:
> On Feb 3, 2:19 pm, Ed Morton<mortons...(a)gmail.com> wrote:
>> On 2/3/2010 5:30 AM, lbrt...(a)gmail.com wrote:
>>
>>
>>
>>> I have some script to find files that works just fine and looks like this:
>>> ~
>>> #!/bin/bash
>>
>>> # FIND SEARCH DIRECTORY
>>> _FND_DIR=/
>>
>>> # EXCLUDING
>>> _XKLD=""
>>
>>> find ${_FND_DIR} -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune -o -type f -printf '%T@,%A@,%C@,"%P"\n'> found.txt
>>> ~
>>> I would like for the whole discriminating section:
>>> ~
>>> -noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune
>>> ~
>>> to be included in a parameter like this:
>>> ~
>>> _XKLD="-noleaf -wholename '/media/sda1' -prune -o -wholename '/proc' -prune"
>>> ~
>>> so that the previou statement looks like:
>>> ~
>>> find ${_FND_DIR} ${_XKLD} -o -type f -printf '%T@,%A@,%C@,"%P"\n'> found.txt
>>> ~
>>> I have searched for a similar example and tried a number of things and none of them worked.
>>> ~
>>> how do you do that?
>>> ~
>>> Thanks
>>> lbrtchx
>>
>> man eval:
>>
>> $ find . -name tmp -print
>> ./tmp
>> $ x='-name tmp'
>> $ find . "$x" -print
>> find: unknown predicate `-name tmp'
>> $ eval find . "$x" -print
>> ./tmp
>>
>> Regards,
>>
>> Ed.
>
> eval did what I needed but created another (new) problem: if you try
> my code you will see eval somehow gets in the way of the "\n" at the
> end working, so it is not producing lines but just a very long one
> liner
>
> How can I produce actual lines for each entry using eval?
>
> Thanks
> lbrtchx

eval causes the shell to parse the line twice so you need to escape "special"
characters like backslashes. Look:

$ printf "%s" "hello"
hello$

$ printf "%s\n" "hello"
hello

$ x="%s\n"
$ eval printf "$x" "hello"
hellon$

$ x="%s\\\n"
$ eval printf "$x" "hello"
hello

Regards,

Ed.


From: Chris F.A. Johnson on
On 2010-02-04, Ed Morton wrote:
....
> $ x="%s\n"
> $ eval printf "$x" "hello"
> hellon$

$ eval printf '$x' "hello"
hello

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====