LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2019, 06:32 AM   #1
CPT-GrayWolf
LQ Newbie
 
Registered: Sep 2019
Location: Colorado USA
Distribution: Fedora
Posts: 14

Rep: Reputation: Disabled
Question Implementing a Custom Shell


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.
 
Old 11-05-2019, 06:55 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by CPT-GrayWolf View Post
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 View Post
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 View Post
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 View Post
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?
 
Old 11-05-2019, 06:56 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
if you want to implement a bash compatible shell you need to check its source code (and documentation).
 
Old 11-05-2019, 07:51 AM   #4
CPT-GrayWolf
LQ Newbie
 
Registered: Sep 2019
Location: Colorado USA
Distribution: Fedora
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
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 View Post
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.
 
Old 11-05-2019, 07:59 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Probably best to start with the POSIX XCU and Korn Shell documentation. Most shells are derived from them, including bash.
 
1 members found this post helpful.
Old 11-05-2019, 08:15 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by CPT-GrayWolf View Post
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 View Post
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 View Post
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.
 
Old 11-05-2019, 08:27 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
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).
 
Old 11-05-2019, 08:55 AM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by pan64 View Post
if you want to implement a bash compatible shell you need to check its source code (and documentation).
FWIW, Microsoft says that the source code for the original Bourne shell is particularly bad.

A rant against flow control macros
 
1 members found this post helpful.
Old 11-05-2019, 09:01 AM   #9
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Here are a few tutorials that came up in a web search:

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
 
1 members found this post helpful.
Old 11-05-2019, 11:02 AM   #10
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by dugan View Post
FWIW, Microsoft says that the source code for the original Bourne shell is particularly bad.

A rant against flow control macros
That example is indeed truly horrid, so I'll let the irony of someone at Microsoft complaining about bad code, slide.

I hate MACROS with a passion.
 
Old 11-05-2019, 11:26 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Mind you, Raymond Chen is not equals to Microsoft: the former is a person, the latter is a company.
 
Old 11-05-2019, 12:09 PM   #12
CPT-GrayWolf
LQ Newbie
 
Registered: Sep 2019
Location: Colorado USA
Distribution: Fedora
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by GazL View Post
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.
 
Old 11-05-2019, 12:27 PM   #13
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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...
 
Old 11-05-2019, 01:03 PM   #14
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by ondoho View Post
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...
There's a shell written in Python...

https://www.oilshell.org/
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Couple questions about implementing shell commands rohando Programming 2 06-29-2008 03:35 PM
Creating custom headers to match a custom kernel utanja Debian 2 06-08-2007 03:15 PM
Custom kernel image on custom slack build using CUSS nykey Slackware 2 07-15-2006 03:05 AM
custom install cd base-config custom mithereal Debian 6 09-11-2005 03:48 PM
custom geforce video card--custom module? bandofmercy Linux - Hardware 3 10-14-2004 06:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration