Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Linda Walsh Newsgroups: gnu.bash.bug Subject: redirecting a file descriptor to an array variable? Possible? How? RFE? Date: Thu, 12 Nov 2015 16:45:49 -0800 Lines: 47 Approved: bug-bash@gnu.org Message-ID: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1447375563 14514 208.118.235.17 (13 Nov 2015 00:46:03 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11873 I'm coming up with a null-record in my brain when I think about this: I'd like to be able to record stdout and stderr without using any temp files into bash array files, AND record the status of the command executed. Something along the lines of Array stderr=() stdout=() runprog () { "RUN" cmd 2>@stderr 1>${stdout[@]}; status=$? ##^-pseudo or ^-syntax return $status } ---- If there is too much output to fit into an array, the same thing would happen as if one did something like readarray ARRAY < <(while :;do echo "lots of lines";done) (i.e. it would eventually overflow something). --- But for the most part, I'm thinking smaller output commands where one just wants to catch fd 1 & 2 and status and have those returned in parameterized arrays and a return value of the cmd or function. I cobbled together something that returned stderr/stdout, and it worked for the simple cases I tried, but it seemed awfully overblown and inflated for what I was trying to do. Then tried to pass back status, and the whole thing fell apart -- at which point, I was thinking -- there's gotta be an easier way that I'm missing -- I seem to be making this a whole heck of a lot more complicated than it needs to be. One thing to remember -- I don't want to use data structures external to bash (like external files), as I can't be sure where I'd be allowed to write them without going through some undesirable kludges... Thanks! -l