[Top][All Lists]

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

Re: ignoring comments in a 'cat' call

From: Bob Proulx
Subject: Re: ignoring comments in a 'cat' call
Date: Thu, 8 Oct 2009 10:00:41 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

Tamlyn1978 wrote:
> I have a file with a list of programs with comments describing what they do,
> e.g.
> unison # file syncronisation
> grass # gis program
> I have a script, which I run as root and includes the command:
> address@hidden:~$ aptitude install $(cat programs) -y
> where 'programs' is the file with the list of programs. Aptitude does not
> ignore the '#' comments, reading them, and the subsequent comment text as
> package files.
> Is there a way to make 'cat' ignore the comments or is there a better
> alternative to cat in this case?

Note that if 'cat' didn't exactly reproduce the contents of input on
the output I would consider that a grave bug.

Instead of using $(cat SOMEFILE) it is better to avoid the extra
process and use $(< SOMEFILE) instead.  It is built into the shell and
is the right way to do that task.

Since you want to post process the file then you should write a script
to do the post processing.  If you want to remove the comments from
the file before using it then approach the problem as you would to do
exactly that task, and then enclose it in $(...).  To remove comments
as in this case I would reach for 'sed'.

  $ sed 's/#.*//' programs

Testing that by itself to ensure that does what you want then you can
use it in the command substitution.

  $ echo aptitude install $(sed 's/#.*//' programs)
  aptitude install unison grass

And then if you are sure it is creating the right command for you then
you can invoke it without the 'echo' and run it for effect.

  $ sudo aptitude install $(sed 's/#.*//' programs)
  Reading package lists... Done

(Of course on my systems I spell 'aptitude' as 'apt-get'.  But that is
a topic for a different mailing list. :-)


reply via email to

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