News for hackers. Stuff that matters.
Re:Hints for writing Unix tools by Animats on Monday October 20, 2014 @10:40PM (#8485670)
1978 called. It wants its pipes back.

That approach dates from the days when you got multi-column directory listings with

  ls | mc
Putting multi-column output code in "ls" wasn't consistent with the UNIX philosophy.

There's a property of UNIX program interconnection that almost nobody thinks about. You can feed named environment variables into a program, but you can't get them back out when the program exits. This is a lack. "exit()" should have taken an optional list of name/value pairs as an argument, and the calling program (probably a shell) should have been able to use them. With that, calling programs would be more like calling subroutines.

PowerShell does something like that.

Re:Hints for writing Unix tools by grosskur on Tuesday October 21, 2014 @01:15AM (#8485992)
You can simulate this with so-called "Bernstein chaining". Basically, each program takes another program as an argument, and finishes by calling exec() on it rather than exit(), which preserves the environment. See:

http://www.catb.org/~esr/writings/taoup/html/ch06s06.html

Or write environment variables to stdout in Bourne shell syntax so the caller call run "eval" on it. Like ssh-agent, for example.

Re:Hints for writing Unix tools by gohrt on Tuesday October 21, 2014 @01:21AM (#8486018)
Re:Hints for writing Unix tools by agumonkey on Tuesday October 21, 2014 @01:20AM (#8486015)
Oh wow, unix continuation passing style. Never heard of that o_o;
Re:Hints for writing Unix tools by oneeyedpigeon on Tuesday October 21, 2014 @04:48AM (#8486482)
I agree that the column formatting code shouldn't be in ls. However, if it were removed (which it won't ever be, of course: theoretical) I would want every system I ever access via a terminal to somehow alias ls to "ls | mc". To support full working of ls, though, that can't just be a straight alias, so I need a shell script to handle things like parameters to ls, which itself is then aliased to ls ... is that really better?
Re:Hints for writing Unix tools by 4ad on Tuesday October 21, 2014 @01:17AM (#8486000)
In Plan 9 programs return strings instead of numeric codes.