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

Re: [OT] - Bash question: get output as a variable?



Stephen Powell wrote:
> On Fri, 5 Feb 2010 10:44:28 -0500 (EST), bruno wrote:
>> Ken Teague wrote:
>>> On Fri, Feb 5, 2010 at 12:39 AM, bruno <bruno.debian@cyberoso.com> wrote:
>>>   
>>>> Why not simply use the  t option for content listing :
>>>>
>>>> tar tvf  * --exclude-from $EXCLUDES
>>>>     
>>> He's already creating the archive with -v.  Why process the archive a
>>> 2nd time just to get a listing when it comes from stdout the 1st time?

---"because" removed---

> 
> This is off topic from the OP's question, but one of the things that I
> miss in the Linux environment that I used to use a lot in the CMS
> environment is CMS Pipelines.  The shell supports pipelines, but they
> are *single-stream* pipelines.  CMS pipelines supports *multi-stream*
> pipelines.  That one feature alone makes CMS Pipelines so much more
> powerful than shell pipelines.  I wish the shell supported multi-stream
> pipelines.
> 
> 

As I'm not familiar with CMS, I have no idea if the following matches or
is completely off target ...

The default pipeline in shells always operates with stdout/stdin, which
is a bit limiting.

But, you can work around it, a bit, like this:

  cat abc_does_not_exist 2>&1 | wc

The 'cat' error message gets sent to wc.  The normal cat output is still
to stdout, so it also would be processed by wc, when the file exists.

The shell also allows you to open your own descriptors to files, using:

  exec 5>abc
  date >&5
  cat abc
  Fri Feb  5 09:15:15 PST 2010

Or, you can set the descriptor to point to another one:

  exec 5>&1
  date >&5
  Fri Feb  5 09:15:15 PST 2010

You can also create "named pipes" using 'mknod a_name p'.  For example:

  mknod fifo1 p
  mknod fifo2 p
  tr '[A-Z]' '[a-z]' < fifo1 >fifo2 &
  [1] 25269
  echo ABCDEFG > fifo1
  cat fifo2
  abcdefg
  [1]+  Done                    tr '[A-Z]' '[a-z]' <fifo1 >fifo2

Perhaps one or another of the above will do what you want?

-- 
Bob McGowan


Reply to: