help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Commands run via xargs and bash returns different result


From: Richard Taubo
Subject: Re: [Help-bash] Commands run via xargs and bash returns different results
Date: Tue, 4 Feb 2014 01:50:24 +0100

On Feb 4, 2014, at 1:10 AM, Bob Proulx <address@hidden> wrote:
—snippets—
> <chuckle/>
> 
> When I searched the web for mdfind I found people asking if there was
> a free(dom) version of mdfind and the answer I found there was no that
> it was unique to Mac OS X.  That makes it impossible to run on a
> free(dom) software system.  (I always try to be clear that free
> software is about freedom and not about no cost.)  Since this is a GNU
> list after all it would be nice if the examples were available to run
> on such a system. :-)  I would do the same in reverse if I were asking
> on an Apple list.

Yes, I agree. I should have tested it out in gnu find as well.


> 
>>> Hmm...  Why are you using a full hard coded path to /usr/bin?  Why not
>>> just "mdfind" and "xargs"?  Is /usr/bin not in your PATH?  If not then
>>> it should be.  Hard coded paths are Evil.
>> 
>> Do you mean Evil as in “Eval is evil” or due transportability issues?
> 
> Evil due to portability issues.  Two of the worse offenders are grep
> and basename.  Different systems put them in different directories.
> Some in /bin and some in /usr/bin.  But the same could apply to
> needing a locally compiled version from /usr/local/bin of some a
> program such as to acquire a newer version of it than offered by the
> system.  Or maybe it is one of the systems that uses /opt/foo/bin for
> various software (possibly with "foo" being "gnu").
> 
> Hard coding paths causes software to be very rigid.  Basically it says
> that it was written for exactly one system and should never work on
> any other system.  And often that means not on future versions of the
> same system as things change from version to version.  Rigid software
> is fragile software.
> 
> And usually when someone capitalizes something like Evil you should
> think of a voice like Vincent Price's saying it and then laughing
> maniacally.  (mwahahaha)

He-he. I will keep that in mind!

> 
>> By setting: my_path="{}” I was trying receive each of the paths
>> handed over from mdfind via xargs, and then use this variable to
>> create html list based output, e.g something like:  
>>      "<li>$my_path</li>”
>> (it was a little more complicated than that, e.g. splitting based on
>> forward-slashes, conditional expressions etc, but the output was 
>> meant for html list output).
> 
> Ah...  So you were (probably) wanting the script to emit the same
> string multiple times as in doing a template generator or some such
> and that was beyond the string substitution features of xargs.
> Gotcha!

Maybe I could have exploited xargs via sed or perl more heavily,
but it was easier to accomplish what I wanted through a bash script.


> 
>> Based on your description above, I understand there is a
>> correct/safer/better way to accomplish this, but you would humour me
>> if you would point out the "bizzarity" part of the command. Clunky
>> and error-prone, yes, but what makes it bizarre? I had to somehow
>> grab the output from mdfind, and it seemed to me at the time, using
>> this clunky method, that I could only grab the output using "{}"
>> ...  I am sure I am wrong :-)
> 
> Sorry if I had originally come off as caustic.  I am trying to soften
> it up with the tone in this message.

Not at all. I was just really happy to learn more and you have given me
great info :-)


> Hope this discussion was useful/interesting,

This was both useful and interesting — thanks for the time you put into it!
I now have some neat things to test out the coming weeks.

Best regards,
Richard Taubo


reply via email to

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