Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

capturing stderr to variable.



Gentlemen:

'highlight' seems to have no return value. If you feed it a file who's type it does not recognize, it sends a message to stderr. To create a test for that, I'm doing this:

   $ highlight $filename 2> /tmp/highlight_err
   [ -s "/tmp/highlight_err" ] &&
   echo="Highlighting is active, but the file is not recognized."
   rm /tmp/highlight_err > /dev/null

... which is clumsy. Researching it, I find that there's no simple way to redirect stderr to a variable, or to some other way of capturing the error condition. Suggestions involve things like:

    ... 2>&4 1>&3; } 2>&1 )

... which I'd not use anyway for clarity's sake. Any suggestions? I was wondering, since redirection and piping are (I believe) at about the same level of parsing, one might suppose that " ... 2| " would be legal. That is to say that we could sent stderr to a command as well as to a file.



Messages sorted by: Reverse Date, Date, Thread, Author