From: David Masover Date: 2009-09-21T22:20:43+09:00 Subject: Re: Writing to STDOUT after closing controlling terminal On Sunday 20 September 2009 08:49:56 pm Matt Bleh wrote: > I know it's not enough justification, but doing an "echo 1" from a > backgrounded bash script process doesn't kill the script. That's because your script is badly written. Try this script: #!/bin/sh sleep 5 echo hi || echo $! > output This has exactly the same behavior as your Ruby script, except that you're only capturing the return value of that first echo command. In other words: In a shell script (bash or otherwise), the 'echo' command does indeed get killed. It's just that by default, shell scripts ignore the return values, which means errors are silently eaten. Ruby, on the other hand, raises an exception when something goes wrong. I don't like silent errors, so I usually write shell scripts that look more like this: #!/bin/sh first line && second line && third line && fourth line That way, the script dies at the first error, unless I explicitly handle it. > I understand > that you should redirect STDOUT, but in Ruby should programmers really > need to concern about this? If you don't want to be concerned about this, abstract it away with some sort of logging class. I'm glad Ruby has the same behavior as any other language, when it comes to basic Unix semantics like this -- and I'm glad my output doesn't just silently get eaten when I close the terminal.