r/C_Programming • u/Appropriate_Error986 • Jun 18 '26
Shell in C
I built a small UNIX shell in C as a learning project and just released v0.0.1
Features so far:
- External command execution
- cd
- cd ~
- exit
GitHub: https://github.com/Dhananjay-Jha-1/dsh
I'd highly appreciate feedback on the code structure or anything related to code in general.
The shell is really primitive at this stage and I want to take it forward.
6
Upvotes
•
u/AutoModerator Jun 18 '26
Hi /u/Appropriate_Error986,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
13
u/flyingron Jun 19 '26
Not too shabby at first. A couple of notes:
You might spend some time learning about the shell before you start into these things. "cd ~" isn't a special case of cd. ~ is substituted in the arglist with the home directory before you even figure out which command you are running.
Further, telling your users to "fuckoff" when you make a mistake is hardly enlightening.
You have a lot of duplicated code. Learn to make things into common subroutines or the like rather than copy-pasta all over the place.
Undefined behavior occurs if the user provides more than 64 arguments. I'd pass in the length of argv as a parameter to the parser (or make it grow dyanimcally).
2
u/rias_dx Jun 19 '26
It can't be called a "shell". I think "shell prototype" make more sense...
2
u/opposite-badge Jun 20 '26
If this is a learning project then there is no pressure to make the code better to be used in another user's machine. However, if this is planned to be used by other user's, then taking inspiration from other shells, after your own implementation is done, will be a nice way to learn things about shells, C, or something else.
What I noticed is there are no comments. Please treat programmers including yourself as the user of your code. Make things easier for them by adding comments.
Good Luck!
1
u/Sad_Chemical_231 Jun 21 '26
Do ls next
1
u/Sad_Chemical_231 Jun 21 '26
Do ls