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

Re: OT: bash scripting question -- passing values to ls



On Sat, 03 Jan 2004 23:34:59 -0800, Nano Nano wrote:

> On Sun, Jan 04, 2004 at 02:27:11AM -0500, Matt Price wrote:
>> so I have to do it by hand at the moment.  But shouldn't I be able to
>> automate it with somthing like:
>> 
>> ls < locate charter | grep -i font 
>> ?
>> nothing I try works -- but I can't believe  it's impossible!  any
>> hints?
> 
> I use backticks:
> ls `locate charter | grep -i font` -ld
> 
> Some commands don't like it if you pass zillions of arguments.
> You can also xargs or find, but the syntax is more cumbersome, involving 
> braces {} and crap.  Somebody will probably post that syntax.

Your solution, is, of course, the most obvious and elegant (well IMHO,
anyway).

There's probably no need to use xargs; I just tested a similar command
which returned 1,829 files and it worked OK.

One thing in passing for the casual reader: there is a newer (and IMHO
generally better) syntax than backquotes for command substitution: $(). No
characters between $( and ) are treated specially, and, for me, the huge
advantage is that nesting is easier and more readable: none of that
backslash-backquote stuff to protect the nested command - some of my
scripts with command subs nested 3 deep are *much* more readable :)

However, in this simple case, backquotes are quicker to type than $()
which is probably why Nano used them.  But just for the sake of
completeness:

ls -ld $(locate charter | grep -i font)

or, in his specific case, this would probably work:

ls -ld $(locate *font*charter)

Sorry, feeling a bit talkative this morning, I'll shut up now :)

-- 
....................paul

Programming without a hex editor is like watchmaking without a hammer.




Reply to: