music
OSdata.com: programming text book 

OSdata.com

Forth-like routines for UNIX/Linux shell

summary

    This subchapter looks at a set of Forth-like routines for use in the BASH UNIX (Linux, Mac OS X) shell.

free book on UNIX/Linux System Administration

Teach Yourself UNIX/Linux System Administration and Shell Programming

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating

Google

Forth-like routines for UNIX/Linux shell

    This subchapter looks at a set of Forth-like routines for use in the BASH UNIX (Linux, Mac OS X) shell.

basic approach

    This supplementary material describes a method for creating Forth-like routines for use in the BASH shell.

    The data and return stacks will be stored using a pair of shell variables, one of which is an array and the other is an ordinary scalar variable.

    The Forth-like routines will be created as shell functions.

    Everything will be stored in a shell function file that can be loaded manually or loaded as part of the normal shell start-up.

    Eventually I intend to write two sets of C source code, one that people can commpile into their own copy of the official BASH source code and one that is part of an entirely new open source shell project that doesn’t have the GNU infecting license. This alternative shell will be designed so that it can run on bare metal, allowing it to be used to deploy embedded systems.

stacks

    Forth uses two stacks: the main data stack and the return stack.

    For the purposes of the BASH shell, we will implement both stacks with a combination of a top of stack pointer variable and an array for the stack. The top of stack pointer will hold the array index of the top of the stack. The stack will build up from the array indexed as one. An empty stack is indicated by having the top of stack pointer variable point to the zero index of the stack array variable. The bottom of the stack will actually be the one index of the stack array variable.

    $ export DataStackPointer=0
    $ declare -a DataStack='zero'; export DataStack
    $ export ReturnStackPointer=0
    $ declare -a ReturnStack='zero'; export ReturnStack
    $

    That’s it for the required variables! And, yes, those could all be placed on one line, but I spread them over four lines for additional clarity.

functions

    These are the functions for a Forth-like working environment. Not all of these functions exist in a real Forth. Most of these functions are have modifications from standard Forth. Many standard Forth functions are missing.

    In particular, this approach treats the stack as a stack of objects. No matter how much memory space an object takes up, it only takes up a single stack slot. In a real Forth, data is stored on the stack as raw binary strings, characters, or numbers and the programmer is responsble for keeping track of how much memory every item actually uses.


free music player coding example

    Coding example: I am making heavily documented and explained open source code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action: www.musicinpublic.com/.

    Create your own copy from the original source code/ (presented for learning programming).

    Work on this project is very slow because I am homeless. I am available for work if someone can provide an indoor place to work in Costa Mesa, California, electricity, internet connections, a flat raised working surface (such as a table or desk), a sitting device (such as a chair or stool), and a fully functional reasonably modern used computer. I’m already homeless, so you don’t need to pay me (and I understand how much business people hate the minimum wage law). Just give me a chance to work.


return to table of contents
free downloadable college text book
free downloadable system administrator and shell programming book

view text book
HTML file

Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.

previous page next page
previous page next page

free book on UNIX/Linux System Administration

Teach Yourself UNIX/Linux System Administration and Shell Programming

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
Milo
PO Box 1361
Tustin, California 92781

    At the time I am homeless. This greatly interferes with my ability to create this project, which can help nearly 20 million U.S. college students and more than 150 million students world-wide. I am looking for 30 rich people or corporations willing to donate $10 a month to my church so that the church can provide a place indoors for me to continue work. If you want to donate, please see help project. Thanks much.

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


I do the news as an unpaid volunteer for KOCI 101.5 FM, Newport Beach/Costa Mesa (also available on the web)


Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2012 Milo

    Created: September 3, 2012

    Last Updated: September 3, 2012


return to table of contents
free downloadable college text book
free downloadable system administrator and shell programming book

previous page next page
previous page next page