Live data from Hacker News

A Bourne-style shell built from scratch in 35 minutes [video]

destroyallsoftware.com

1–10 of 71 posts

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#2
On this note, I need to build my own Terminal multiplexer - does anyone have a favorite primer of theirs for all the escape codes? Not only do I need to use them myself, but I need to handle them of child processes to restrict term sizes etc.

I can Google like ya'll - I'm just asking if there are any favorite resources :)

Thanks

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#3
There is more to writing a shell than simply reading commands and executing them after fork()ing. TTY handling must be done right¹ and interrupt and signal handling is rather tricky to get right as well².

(Not to mention, of course, that a Unix shell is very cumbersome to use without pipes and redirection. EDIT: Pipes are implemented, but not redirection?)

1. http://www.linusakesson.net/programming/tty/

2. https://www.cons.org/cracauer/sigint.html

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#4
It supports (1) running commands with arbitrarily many arguments

Wouldn't the size of the arguments be limited by sysconf(_SC_ARG_MAX) as explained here? http://man7.org/linux/man-pages/man2/execve.2.html

PS: Is the code available somewhere? I can't play the video on Firefox on CentOS 6.

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#5

On this note, I need to build my own Terminal multiplexer - does anyone have a favorite primer of theirs for all the escape codes? Not only do I need to use them myself, but I need to handle them of child processes to restrict term sizes etc. I can Google like ya'll - I'm just asking if there are any favorite resources :) Thanks

There are no such things as “the” escape codes. Any terminal could have any codes. You would have to look at the TERM environment variable and use codes appropriate for that terminal. There are, of course, libraries to do this for you, such as terminfo and ncurses. But never output raw escape codes yourself - all the world is not a VT100 or Linux terminal.

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#6
post #3

There is more to writing a shell than simply reading commands and executing them after fork()ing. TTY handling must be done right¹ and interrupt and signal handling is rather tricky to get right as well². (Not to mention, of course, that a Unix shell is very cumbersome to use without pipes and redirection. EDIT: Pipes are implemented, but not redirection?) 1. http://www.linusakesson.net/programming/tty/ 2. https://ww…

I’m not sure if you watched the video or read its description, but pipes are the focus of this implementation. He describes pipes as “the core of the UNIX shell” in the video. I suppose that is somewhat up for debate, but building complex tasks out of composable pieces is certainly up there among UNIX’s design goals, and pipes are a big part of that. OTOH, his implementation does not seem to cover output redirection à la `exec` (file-based, file-descriptor-based, or named-pipe).

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#7
post #6
post #3

There is more to writing a shell than simply reading commands and executing them after fork()ing. TTY handling must be done right¹ and interrupt and signal handling is rather tricky to get right as well². (Not to mention, of course, that a Unix shell is very cumbersome to use without pipes and redirection. EDIT: Pipes are implemented, but not redirection?) 1. http://www.linusakesson.net/programming/tty/ 2. https://ww…

I’m not sure if you watched the video or read its description, but pipes are the focus of this implementation. He describes pipes as “the core of the UNIX shell” in the video. I suppose that is somewhat up for debate, but building complex tasks out of composable pieces is certainly up there among UNIX’s design goals, and pipes are a big part of that. OTOH, his implementation does not seem to cover output redirection…

I read the description, but must have missed the part about pipes; oops.

Re: A Bourne-style shell built from scratch in 35 minutes [video]

#10

On this note, I need to build my own Terminal multiplexer - does anyone have a favorite primer of theirs for all the escape codes? Not only do I need to use them myself, but I need to handle them of child processes to restrict term sizes etc. I can Google like ya'll - I'm just asking if there are any favorite resources :) Thanks

I did some research a while back and what i recall is that Xterm is the Gold Standard, supporting more escape sequences than anything else. So, if you can come even close to what Xterm supports you're good. PDF of xterm control sequences https://www.x.org/docs/xterm/ctlseqs.pdf This site is good to for explaining xterm's behavior: http://invisible-island.net/xterm/ and how it came to be what it is and support what it does.

I've seen claims that current command line tools are standardizing around the ECMA-48/ISO 6429/ANSI X3.64 escape code protocol

Post reply on HN