On Wed, Nov 3, 2010 at 3:20 PM, Paul Heinlein <[email protected]> wrote:
> On Wed, 3 Nov 2010, Russell Senior wrote:
>
>>>>>>> "Dan" == Dan Young <[email protected]> writes:
>>
>> Russell> Or an equivalent alternative:
>> Russell> rpm -e $(cat rmlist)
>>
>> Dan> UUOC! ;-)
>>
>> Dan> xargs rpm -e < rmlist
>>
>> D'oh!  But, you are cheating by adding xargs!
>>
>>  russ...@donk:~$ ls -l /usr/bin/xargs /bin/cat
>>  -rwxr-xr-x 1 root root 26860 2008-04-04 07:22 /bin/cat
>>  -rwxr-xr-x 1 root root 34516 2008-04-03 10:41 /usr/bin/xargs
>>
>> See, /bin/cat is smaller! ;-)

But, but, but what if you are passing in thousands of arguments?
Interestingly, /bin/echo seems to handle overrunning ARG_MAX, though I
don't know about rpm.

cat is fewer system calls, though:
[dyo...@dyoung tmp]$ strace echo $(cat rmlist) >/dev/null 2>/tmp/cat;
wc -l /tmp/cat
37 /tmp/cat
[dyo...@dyoung tmp]$ strace xargs echo < rmlist >/dev/null
2>/tmp/xargs; wc -l /tmp/xargs
52 /tmp/xargs

So -1 to me for being pedantic. ;-)

But xargs completes faster:

[dyo...@dyoung tmp]$ seq 1000000 > /tmp/1000000
[dyo...@dyoung tmp]$ time echo $(cat /tmp/1000000) > /dev/null

real    0m2.293s
user    0m2.150s
sys     0m0.149s
[dyo...@dyoung tmp]$ time xargs echo < /tmp/1000000 > /dev/null

real    0m0.534s
user    0m0.197s
sys     0m0.403s

> In its "Command Substitution" subsection, the bash(1) man page even
> makes a special point of calling out this circumstance: "The command
> substitution $(cat file) can be replaced by the equivalent but faster
> $(< file)."

Nice! I hadn't ever thought of that.

-- 
Dan Young
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to