-1

I have this bash function:

zmx () { 

 "$@" 2> >( while read line; do echo -e "r2g: $line"; done ) > \
     >( while read line; do echo -e "r2g: $line"; done )

}

what it does is append "r2g:" to each line of stdout/stderr.

You use it like so:

$ zmx echo "foo"

and you will get:

r2g: foo

It works great in Bash4, but seems to break with Bash3 when running on a Mac.

Does anyone know how to convert it to idiomatic Bash3?

closed as unclear what you're asking by Michael Homer, Jesse_b, G-Man, Jeff Schaller, thrig Jul 8 '18 at 15:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is it giving an error in bash v3? – Jesse_b Jul 7 '18 at 0:15
  • it's a syntax error, yeah, will update the OP – Alexander Mills Jul 7 '18 at 0:34
  • seems to work for me on macos using bash v3.2. – Jesse_b Jul 7 '18 at 0:39
  • Do you mean that it's supposed to "prepend" r2g: to each line? Appending it would put it at the end. – Nasir Riley Jul 7 '18 at 3:18
  • What is the error it gives you? – Michael Homer Jul 7 '18 at 5:02
1

work on bash 3.2.57

MacBook-Pro:~ em$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

MacBook-Pro:~ em$ zmx() { "$@" 2> >(while read line;do echo -e "err: $line"; done ) > >(while read line; do echo -e "std: $line"; done); }
MacBook-Pro:~ em$ zmx bash -c "ls -1 /etc/ | head -5 ; cat /etc/shadow"
std: afpovertcp.cfg
std: afpovertcp.cfg~orig
std: aliases
std: aliases.db
std: apache2
err: cat: /etc/shadow: No such file or directory

Not the answer you're looking for? Browse other questions tagged or ask your own question.