need help w/ simple bash script

Paul Chvostek paul+fbsd at it.ca
Tue Jun 27 12:21:45 UTC 2006


Hiya.

I've been working on a web front-end to aggregate multiple servers'
package update requirements as well.  I'll probably have it ready to
present in another few weeks, if ${DAYJOB} doesn't get in the way.

On Tue, Jun 27, 2006 at 08:01:49AM -0400, dw wrote:
> 
> # REPORT=`pkg_version -v`
> 
> But when I "echo $REPORT", I get:
> 
> Xaw3d-1.5E_1 = up-to-date with port apr-db42-1.2.7_1 = up-to-date with 
...
> When what I want is:
> 
> Xaw3d-1.5E_1 = up-to-date with port
> apr-db42-1.2.7_1 = up-to-date with port
...

Use more quotes.

  REPORT = "`pkg_version -v`"

will protect the newlines.

> for LINE in `pkg_version -v`; do echo $LINE; done

If you feel adventurous, you could to try something like this:

  tmpfile=/tmp/`basename $0`.$$
  trap "rm -f $tmpfile $tmpfile.?" 0 1 2 3 5 15
  pkg_version -v | while read package status text; do
    echo "$package $text" >> $tmpfile."$status"
  done

Now you have tempfiles with package lists for the various stati, which
you can parse as you see fit.

Note that you may get better (i.e. more useful) mileage out of something
like:

  pkg_version -vL=

which will show you only what needs to be updated.

-- 
  Paul Chvostek                                             <paul at it.ca>
  it.canada                                            http://www.it.ca/



More information about the freebsd-questions mailing list