How to get started writing a toy shell?

I had posted months ago asking for help thinking of a toy "systems" programming project to do in Rust.

A kind member of the community suggested writing a simple shell:

The point here is to figure out how to use system libraries ( nix for Linux, winapi for Windows), because that is something that is not really done in Python or Javascript (it could be, but it isn't).
For example: when you type emacs & on the terminal (using bash shell, perhaps), you see a new window of Emacs pop up, and a new prompt arrives. But how does it actually work? Can you write a program that does this? (Note that using the C system() function is cheating, since that just calls into bash , more or less)

Can someone give me a direction here? I understand not calling out to the shell using system in C because that is "cheating"...but what does, "..how to use system libraries" mean? Is nix a C API for interacting with the OS and should I be looking at a crate for Rust like: nix - Rust?

Say your shell has a built-in command to create links -- both hard links and soft links (and potentially other types of links). How would you implement that?

(I chose creating links as an example specifically because the semantics differ on Windows and Unix-like platforms).

You mean just call something like this: std::os::unix::fs::symlink and std::os::windows::fs::{symlink_file, symlink_dir}

If so, the interesting bit is parsing the command line and dispatching to the right system call?

Those will only allow you to create symlinks, I should probably have emphasized that you may want to support all link types. (It gets kind of hairy in Windows, and the standard library will not suffice).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.