Live data from Hacker News

Building a Shell

healeycodes.com

11–20 of 49 posts

Re: Building a Shell

#15
post #2

Bit of pedantry but I don't think traditional unix shell (like this) follows repl model; the shell is not usually doing printing of the result of evaluation . Instead the printing happens more as a side effect of the commands.

I remember my first shell programming I ever did was batch in windows back in the 3.11/95 days.

The first line was always to turn off echo, and I've always wondered why that was a decision for batch script. Or I'm misremembering. 30 years of separation makes it hard to remember the details.

Re: Building a Shell

#17
post #2

Bit of pedantry but I don't think traditional unix shell (like this) follows repl model; the shell is not usually doing printing of the result of evaluation . Instead the printing happens more as a side effect of the commands.

It’s a shell, not the whole thing. The whole thing is the shell+kernel+programs.

Re: Building a Shell

#18
post #16

Fun read. Wonder if you are able to edit text in the shell, or if you need to implement a gap buffer to allow it?

Editing the current line works because I brought in https://man7.org/linux/man-pages/man3/readline.3.html towards the end so I could support editing, tab completion, and history.

IIRC readline uses a `char *` internally since the length of a user-edited line is fairly bounded.

Re: Building a Shell

#19
post #2

Bit of pedantry but I don't think traditional unix shell (like this) follows repl model; the shell is not usually doing printing of the result of evaluation . Instead the printing happens more as a side effect of the commands.

I remember my first shell programming I ever did was batch in windows back in the 3.11/95 days. The first line was always to turn off echo, and I've always wondered why that was a decision for batch script. Or I'm misremembering. 30 years of separation makes it hard to remember the details.

Echo in that case prints command lines before executing them. Its analog is `set -x` rather than `echo`.

Re: Building a Shell

#20
post #16

Fun read. Wonder if you are able to edit text in the shell, or if you need to implement a gap buffer to allow it?

Editing the current line works because I brought in https://man7.org/linux/man-pages/man3/readline.3.html towards the end so I could support editing, tab completion, and history. IIRC readline uses a `char *` internally since the length of a user-edited line is fairly bounded.

Very cool. Currently working on the beginning of a small text editor so this part seemed interesting and was curious of any overlap. Thanks for the interesting post!
Post reply on HN