# A quick Mac OSX question

**URL:** <https://www.ruby-forum.com/t/a-quick-mac-osx-question/157322>\
**Category:** Ruby\
**Created:** [January 9, 2009, 12:11pm UTC](https://www.ruby-forum.com/t/a-quick-mac-osx-question/157322 "2009-01-09T12:11:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 9, 2009, 12:11pm UTC](https://www.ruby-forum.com/t/a-quick-mac-osx-question/157322/1 "2009-01-09T12:11:44Z")

</div>

Does mac osx supports the “2\>&1” syntax to redirect stderr?

In other words, does the following line of code work as expected in mac  
osx?

output = `some_command 2>&1`

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 9, 2009, 12:24pm UTC](https://www.ruby-forum.com/t/a-quick-mac-osx-question/157322/2 "2009-01-09T12:24:23Z")

</div>

On Jan 9, 2009, at 6:11 AM, Albert S. wrote:

> Does mac osx supports the “2\>&1” syntax to redirect stderr?
> 
> In other words, does the following line of code work as expected in  
> mac  
> osx?
> 
> ## output = `some_command 2>&1`
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Yes:

ratdog:~ mike$ uname -a  
Darwin ratdog.local 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24  
17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE\_I386 i386  
ratdog:~ mike$ irb

> > output = `perl -e 'die "Aaargh!"'`  
> > Aaargh! at -e line 1.  
> > =\> “”  
> > output = `perl -e 'die "Aaargh!"' 2>&1`  
> > =\> “Aaargh! at -e line 1.\n”

–

Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.stok.ca/~mike/](http://www.stok.ca/~mike/)

The “`Stok’ disclaimers” apply.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 9, 2009, 1:30pm UTC](https://www.ruby-forum.com/t/a-quick-mac-osx-question/157322/3 "2009-01-09T13:30:46Z")

</div>

Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Does mac osx supports the “2\>&1” syntax to redirect stderr?
> 
> In other words, does the following line of code work as expected in mac  
> osx?
> 
> output = `some_command 2>&1`

As long as you use bash instead of tcsh, yes.

bash -c ’ output = `some_command 2>&1` ; echo “$output” ’

Notice than nowdays we can use $(some\_command 2\>&1) instead of the  
backquotes, which is nice because you can nest them:

bash -c ’ msg=$(printf “%dnd result = %s” $(( 1 \* 2 \* 3 \* 7 )) “$(echo  
“Do not panic”)” ) ; echo “$msg” ’  
42nd result = Do not panic

Or use chsh to switch to bash:

> **[MacShadows.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=macshadows.com)**
>
> Friendly and helpful customer support that goes above and beyond. We help you get the perfect domain name.
