I'm buidling my own shell and I was trying to implement a history function, but was a little lost on where to start. I know i would like to use a for loop to go through list, I'm just having trouble on where to store it.

Recommended Answers

All 2 Replies

You could do like bash and keep it in a 'hidden' file in the user's home directory (bash uses ~/.bash_history).

If you want to quickly access past commands, however, you probably want to keep the most recent N commands in memory and only flush them to disk periodically.

I'm curious if your shell is merely echoing commands to another shell. What does this shell do with the commands it receives? Are they translated into a system API or some library?

Knowing this would help in deciding the best way to manage the command history.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.