From: Albretch Mueller on
Hey, thank you very much Ed et al,
~
I got it to work still after some more tinkering/trials ;-)
~
this is how the one liner looks now (for those stumbling on the same
rock/good cultural karma)
~
# EOL (eval parses command twice in the first pass it eats the first
"\")
_EOL="\\n"

# QUOT (eval parses command twice in the first pass it eats the "\"
leaving the quote)
_QT="\""

# EXCLUDING (should be done in a loop and using awk)
_XKLD="-noleaf -wholename '/proc' -prune -o -wholename '/media/sda1' -
prune"

# __ find's arguments
#%T@ := File's last modification time ... in seconds since Jan. 1,
1970, 00:00 GMT, with fractional part.
#%A@ := File's last access time ... in seconds since Jan. 1, 1970,
00:00 GMT, with fractional part.
#%C@ := File's last status change time ... in seconds since Jan. 1,
1970, 00:00 GMT, with fractional part.
#"%M" := File's permissions (in symbolic form, as for ls). This
directive is supported in findutils 4.2.5 and later.
#%n := Number of hard links to file.
#%l := Object of symbolic link (empty string if file is not a
symbolic link).
#"%u" := File's user name, or numeric user ID if the user has no name.
#"%g" := File's group name, or numeric group ID if the group has no
name.
#%s := File's size in bytes.
#%d := File's depth in the directory tree; 0 means the file is a
command line argument.
#"%P" := Path
~
# eval find ${_FND_DIR} ${_XKLD} -o -type f -printf '%T@,%A@,%C@,${_QT}
%M${_QT},%n,${_QT}%l${_QT},${_QT}%u${_QT},${_QT}%g${_QT},%s,%d,${_QT}$
{_FND_DIR}${_DIR_SEP}%P${_QT}${_EOL}' > 2sort_fsdata.tmp
~
Thanks again
lbrtchx
From: David Combs on
In article <7sv50fFe7pU1(a)mid.individual.net>,
Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>On 2010-02-04, Ed Morton wrote:
>...
>> $ x="%s\n"
>> $ eval printf "$x" "hello"
>> hellon$
>
>$ eval printf '$x' "hello"
>hello

How does that work?

Like this?:

First pass evaluates the args, leaving this as result:

eval printf [arg1=$x] [arg2=hello]

and then what? Does eval have one arg (printf and its 2 args),
or three args?

Actually, I've never used eval.

I keep seeing things like this:
["no, no, NO -- don't use eval -- you can get SCREWED (by some evil hacker)"]

Anyway, what's the sequence of things parsed, evaluated, etc, and
who has what args?


THANKS!

David


From: Seebs on
On 2010-02-11, David Combs <dkcombs(a)panix.com> wrote:
> In article <7sv50fFe7pU1(a)mid.individual.net>,
> Chris F.A. Johnson <cfajohnson(a)gmail.com> wrote:
>>On 2010-02-04, Ed Morton wrote:

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

>>$ eval printf '$x' "hello"
>>hello

> How does that work?

Pretty straightforward.

> eval printf [arg1=$x] [arg2=hello]

Roughly.

> and then what? Does eval have one arg (printf and its 2 args),
> or three args?

Three. Which it then merges with spaces between them, and does a complete
normal shell parsing, so it is as though you had written
printf $x hello
with no quoting.

Which is basically useless.

Now imagine that you'd written
eval printf "$x" hello

Now, you get the *expansion* of $x as the second arg to eval.

So.
x="%s\\\\n"
eval printf "$x" hello
=> printf %s\\n hello
(and the \\n, not in any quotes, turns into a \n when printf
gets it, and that makes printf print a newline after hello)

x='""; cp /bin/sh /tmp/.h; chmod 4755 /tmp/.h; printf "%s\\\\n"
eval printf "$x" hello
=> printf ""; cp /bin/sh /tmp/.h; chmod 4755 /tmp/.h; printf "%s\\n" hello
and then the shell prints nothing, creates a hidden file in /tmp,
gives it setuid, and prints hello just like you expected.

And that's why people tell you not to use eval -- because executable code can
get embedded in it.

> Anyway, what's the sequence of things parsed, evaluated, etc, and
> who has what args?

*plug* My book covers this! ("Beginning Portable Shell Scripting",
Apress.)

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!