shell scripting problems

George Davidovich freebsd at
Sat Nov 29 02:39:48 PST 2008

On Fri, Nov 28, 2008 at 11:31:17PM -0700, Tim Judd wrote:
> On Fri, Nov 28, 2008 at 11:08 PM, Sahil Tandon <sahil at>
> wrote:
> > Tim Judd <tajudd at> wrote:
> > 
> > I am not sure what the problem is, but are you just looking for the
> > output of "pkg_info -qxL" on the *first* instance of xorg-fonts-*?
> > 
> > % pkg_info -qL `pkg_info | grep xorg-fonts | head -1 | cut -d\  -f1`
> > 
> > FWIW, your regexp also looks faulty.
> I'm sure it's faulty
> Which is why I'm asking for help

What you were asking wasn't clear, and could have included a script
problem, a port update problem, a pkg_info problem, and/or a regex
problem.  And then, I'm scratching my head wondering how you're making
use of the output of the -L switch.

> My regexes (in it's various forms) produce the output similar to:
>   xorg-fonts-75dpi
>   xorg-fonts
>   xorg-fonts-100dpi
>   ...
> and I'm wanting my regex to return the 2nd value, in this example, in
> this list.

If that's the case, where does your regex of "^$PKG-[0-9,._]+$" fit into
all this?  And why would you expect pkg_info to match on something like
'^xorg-fonts$' when, AFAICT, there is no port by that name?  Again,
you're not being clear. 

> The problem is the shell is taking the end anchor $ as the start of a
> variable, and no matter how I escape it, it seems to never work.

The end-of-line anchors work fine.  For the following I've used bash,
but you can copy the same into a /bin/sh script for identical results:

	# PKG=cyrus

	# pkg_info -Ex $PKG

	# pkg_info -Ex $PKG.*1

	# pkg_info -Ex ^$PKG.*1\$

I'd suggest you submit your script or an abbreviated version.


More information about the freebsd-questions mailing list