Shellton : a shell story

Yared Torres
1 min readApr 15, 2021

--

What happens when you type “ls -l *.c” in a shell?

Photo by Alex Knight on Unsplash

Basics of shell

So our shell goes through a few process in order to run. Shell takes inputs from standard input, parses them, and then passes them to the kernel to be executed.

The prompt

First we create an infinite loop in order to run a prompt within it. Our prompt will take in the user input using the getline() function. So typing “ls -l *.c” will store that whole string.

Parsing

Next, using the strtok() function we can parse our user input and create individual tokens that can be stored and interpreted as commands.

Executing

The tokenized string then gets passed through the child process of our shell and ran with the execve() function. This passes the tokenized commands and its arguments to the kernel, then returns to the infinite loop where the prompt will be up waiting for user input.

Conclusion

So, “ls -l *.c” will list all the files that end with .c in our cwd in long format.

--

--

Yared Torres
Yared Torres

No responses yet