ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So, if I were trying to write my own implementation of a fully bash-compatible UNIX shell, what standards and/or functionalities should I be aware of, and where would I look for the best information?
Also, would there be any perceived downside to using a language other than C? Perhaps Go or Rust?
I have no problem with C. In fact, I'm most familiar with it. But I'm curious about the implications of the use of other languages in building such system utilities, and how it might affect development as well as the end-user's experience.
So, if I were trying to write my own implementation of a fully bash-compatible UNIX shell, what standards and/or functionalities should I be aware of, and where would I look for the best information?
Recommend you look at the standard and/or functionalities in existing shell languages to begin your list of requirements, and then add/remove things where you determine there can be enhancements/benefits.
Quote:
Originally Posted by CPT-GrayWolf
Also, would there be any perceived downside to using a language other than C? Perhaps Go or Rust?
I don't know Go or Rust really well. Rust is focused on safety, or that was it's intent, it is C++ derived. Go was invented at Google, I don't care to necessarily eschew something because it came from a certain place.
But like you:
Quote:
Originally Posted by CPT-GrayWolf
I have no problem with C. In fact, I'm most familiar with it.
However I'm less this:
Quote:
Originally Posted by CPT-GrayWolf
But I'm curious about the implications of the use of other languages in building such system utilities, and how it might affect development as well as the end-user's experience.
Primarily because I've used C#, Objective-C, meaning various platform languages for specific things like Apple or Microsoft.
A language is a language. Add it to the pile.
I decided to use those native languages in their native environments because I tried programming for Windows using other libraries and there were technology gaps that I was endlessly working through. While there were numerous quirks using their native tools, they only stood in my way, by way of obscurity versus stood in my way because they didn't have support for something. Sorry I don't know if that makes much sense, but in all honesty Qt was great, but when I tried to access the user's root drive and home location or seek what types and how many serial ports there were on a system, it was jumping through a flaming hoop, doing a back flip. Not that MSVC was all that big of a picnic, but there's (exaggerating) 80 ways to access a serial port in there, so that's the over-problem sometimes with their native tools. Which way is right?
Recommend you look at the standard and/or functionalities in existing shell languages to begin your list of requirements, and then add/remove things where you determine there can be enhancements/benefits.
I don't know Go or Rust really well. Rust is focused on safety, or that was it's intent, it is C++ derived. Go was invented at Google, I don't care to necessarily eschew something because it came from a certain place.
I'm just curious is there are any specific standards used by bash (Perhaps there are some POSIX standards or something used by UNIX shells that I should be aware of).
I don't intend to remove any bash functionality. Thinking more of a drop in replacement for bash with added functionality.
As far as I'm aware Go also puts emphasis on safety while also including functionality intended to make parallelization much easier, which I imagine might come in handy when writing something like a shell. It's goal seems to be safe and easy parallel processing while keeping things as fast as possible.
Rust seems to focus more on trying to act as a replacement for C/C++ with the advantage of added safety. So, as fast as possible, with all the low-level functionality you might need.
I've been meaning to learn more languages. Seems no one in Denver cares about C programmers, and knowing more languages is just generally useful. Having an excuse would be a good incentive.
Quote:
Originally Posted by pan64
if you want to implement a bash compatible shell you need to check its source code (and documentation).
I'm not really aiming for a source clone. I really just need to copy it's functionality.
I'm fine with checking the code for ideas on implementing functionality if I'm stuck, but for the most part, I just need a detailed look at how it acts under given circumstances.
Copying the functionality isn't too hard. I just want to know that I'm not overlooking anything (Both in syntax, and in how the shell interacts with the OS).
I guess I'm just looking for anything specifically giving a standard for the bash style syntax, or for the behaviour of the shell in a POSIX environment? Even some generally accepted rules for shell implementation would be nice.
I'm just curious is there are any specific standards used by bash (Perhaps there are some POSIX standards or something used by UNIX shells that I should be aware of).
Dual answer (1) none that I'm aware of, (2) bash uses the benefits of regex, but I believe python does the same.
Quote:
Originally Posted by CPT-GrayWolf
I don't intend to remove any bash functionality. Thinking more of a drop in replacement for bash with added functionality.
Then stick with bash.
Quote:
Originally Posted by CPT-GrayWolf
I've been meaning to learn more languages. Seems no one in Denver cares about C programmers, and knowing more languages is just generally useful.
I can agree that "being capable of contending with other languages" has helped me, but I've been using C for 30+ years and currently use exactly that. I work with a great deal of developers in Boulder who program in C. I think really it boils down to the market where you work and seek work. For me it has always been embedded development.
If you want to understand how does bash work you may need to check the source code. I don't meant to copy it. Just to understand. Bash itself it relatively complex.
From the other hand you may try the tests written for bash and you can test your own shell (if it passes too).
As for the language: you're probably going to to use readline to take input and fork/exec to launch programs. You can use any language that gives you access to those. There are no real technical considerations (to the language choice) apart from that.
Last edited by dugan; 11-05-2019 at 01:11 PM.
Reason: Added the Rust tutorial
Probably best to start with the POSIX XCU and Korn Shell documentation. Most shells are derived from them, including bash.
The XCU is exactly the sort of thing I was looking for!
I knew there had to be something in the POSIX specification. I just wasn't sure where to look.
Actually the entire XCU looks like it would be generally useful to have.
And after only 650 pages my printer now sounds like some dying animal begging for someone to end its suffering.
I wonder if it would be possible to write a shell in a high level scripting language like, say, bash?
I guess one would have to take care to actually re-implement every bit of it, not just pass it through...
I wonder if it would be possible to write a shell in a high level scripting language like, say, bash?
I guess one would have to take care to actually re-implement every bit of it, not just pass it through...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.