A quick Mac OSX question

A

Albert Schlef

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`
 
M

Mike Stok

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`

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$ irbAaargh! at -e line 1.
=> ""=> "Aaargh! at -e line 1.\n"


--

Mike Stok <[email protected]>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
 
P

Pascal J. Bourguignon

Albert Schlef said:
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:
http://www.macshadows.com/kb/index.php?title=Changing_your_shell_on_Mac_OS_X
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top