GregDavidson / BashSimples

BASH Profile Scripts and Simples Loadable Module System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Directory: ~/Gits/Shell-Profiles

Posix-Shell Profile and Utility Scripts

This is a collection of scripts for Posix-Compatible Shells which can support configuring and extending an Operating System, especially a User Account.

If you would like to know more about this project

  • see CONTEXT section below for my motivations for this project
  • see STORY section below for how these things came to be
  • see GLOSSARY section below for definitions of most of the technical terms

If you’re reading this on github, alas, github doesn’t yet understand

  • Document Section Folding
    • so this document may seem rather long
    • which is why I’ve put the optional sections at the bottom
  • Links to internal sections of documents
    • so you’ll have to manually scroll down to the various sections

Let’s start with the most important parts!

Profiles (put these in your home directory)

Profile ScriptPurpose
.xprofilesymbolic link to .profile for X Display Managers
.profilesourced by accounts using sh workalike shells
.bash_profilesourced at start-up by login bash
.bashrcsourced at start-up time by non-login bash
.profile.d/sample scripts for your extensions
.bash_profile.d/sample scripts for your extensions

You can install these things automatically either by running or studying and following these provided scripts:

Bin/install-profiles
Bin/install-dotfiles

Simples System

Use the Simples System which is right for you:

Simples-Sh
a system to manage sh extension modules
  • Will work for any Posix-Compatible Shell
  • Is not as advanced as Simples-Bash
Simples-Bash
a system to manage bash extension modules

The Simples modules allow you to selectively add desirable functionality to your environment for interactive usage and for your scripts.

Simples CommandPurpose
simple_require module-nameloads module module-name if not present
simple_source module-nameloads module module-name unconditionally
$simples_bash_path/Bin/*scripts to test simples modules

Notes:

  1. The term simple used to refer to a remedy for a problem.
  2. There are Simples Systems for multiple shells
    • The fundamental Simples Functions should behave the same
  3. You can help extend the Simples System
    • Please add any new features to each Simples System
      • with the same behavior
    • Porting the Simples System to additional shells

CONTEXT

I aim to make computer systems

  • more powerful for power users
  • with minimal added or even less complexity

Let’s extend the basic functionality of computer systems and subsystems so that they are

  • easier to understand than before
  • more powerful than before
  • and easier to further extend if necessary

This is all a part of Computing Magic!

Power User
Someone who empowers themselves in interesting and creative projects by delegating undesirable non-creative work to computers.

STORY

The Simples System

  • Origin Story
  • Possible Future

Origin of the Simples System

Late last millennium (the 4-digit years beginning with a 1 instead of a 2) the author found himself needing to use several similar but annoyingly different shells on different Unix-like platforms.

ProgramNameWhat is was aboutProsCons
shMashey shellEarly Unix shellbetter than nothingmediocre all around
shBourne ShellMore Elegant ShellGood for Scriptingmediocre at interactive use
cshC ShellNicer ShellOK for scriptingBetter for interactive use
kshAT&T Korn ShellBetter all aroundGreat scriptingAT&T Proprietary :-(
pdkshPublic Domain kshSubset of AT&T kshGood for ScriptingOK for interactive use
POSIXshell standardSubset of pdkshEnables portabilityMissing useful features
BashGnu BashPower & FreedomOk for scriptingGood for interactive use
tcshT-Shella better cshMore nice featuresNot POSIX Compliant
ksh93latest kshBetterFinally Open Source!Dated
zshZ ShellFeatures GaloreMany wonderful featuresToo complex for some!

At the time this project was begun, the David Korn’s wonderful ksh was still proprietary and zsh was obscure - or at least obscure to me! I found myself having to constantly adapt to the annoying differences and missing features of the shells I was using. I couldn’t write good scripts which would work in any shell. Fortunately, most of the shells supported Shell Functions, i.e. they were programmable - so I should be able to do something about this mess!

I began the Simples Project by writing a set of shell functions to deal with common issues in scripting, e.g. managing lists. I wrote a version of those functions for the Bourne Shell sh, the Public Domain Ksh and an early version of Bash. I created a shell-independent module system, called Simples to manage modules consisting of logical groups of such functions.

With the Simples System I could now write nicer, higher-level and more portable scripts with any of the shells I had to contend with. And now, thanks to GitHub, so can you!

You’d think that by now it would be possible to just do everything in one modern shell, e.g. bash which is the most ubiquitous. Alas, lately, many Gnu/Linux Graphical Desktops ignore a user’s shell setting and use sh for their login scripts. Until recently, sh on Gnu/Linux systems was usually just a link to bash. Alas, many Gnu/Linux distributions now link sh to dash, a new sh compatible shell which has the unique misfeature that it strips the environment of any exported shell functions from a bash login profile. Sigh! Fortunately, the last problem can be reversed if you have system administration privileges!

There are some morals to this story:

  1. When you are provided with programmable tools which imperfectly meet your needs and aspirations, raise the level of your tools with some modest programming, making them both more powerful and more consistent.
  2. Keep what you do compatible with what the rest of the system expects unless you want to have to fork the whole system and maintain it forever!

In addition to solving my own needs, I hope that this powerful yet portable Simples system is useful to you and might also inspire you in your own creative endeavors!

Posix-Compatible Shells vs. Other Shells

ksh seems to be the best Posix-compliant shell for scripting. zsh has the most features for interactive use and is a close second in scripting power. Using bash from emacs provides an especially nice interactive experience. emacs is also a nice platform for developing scripts and programs in much nicer languages. Frankly, writing any but the most trivial scripts in any of these shell languages is probably a bad idea!

There are a variety of Non-Posix Shells which are in some ways better for

If you choose to use these or other Non-Posix Shells you’ll still probably have to use Posix-Shells for some purposes, but you won’t have as much need to learn the advanced features of the Posix-Shells.

Future Plans

I am keeping my eye on many new developments in programmable user interfaces and nice scripting languages.

One of the least known yet most productive scripting and GUI languages is tcl whose native GUI toolkit ttk has been adopted by more popular scripting languages, including Python, Ruby and Perl. If you use any of those languages, check out tkinter!

Some of the newer Lisps are great for scripting and have spawned shell projects, e.g.

Alas, none of these shells support sh syntax and semantics and therefore none of them can replace sh in all of the Posix environments which expect such. Sigh!

It’s not really necessary to use the same tool for issuing interactive commands and writing scripts.

I consider the pdksh versions of the Simples System to be obsolete. I have no plans of porting the Simples System to zsh. I have no interest in new non-POSIX-compliant shells - sorry tcsh and fish! I would have abandoned the sh port if it weren’t for the regression of X Display and Session Managers now ignoring a user’s specified shell in favor of sh.

I have no ambitious plans for the Simples System. I will try to keep the sh and bash Version of the Simples System safe from software rot and occasionally incorporate minor improvements, especially those that become available as bash evolves. (It would be really nice, e.g. if Chet would fix the horrible -n nameref botch!)

I am interested in your constructive feedback and any pull requests you may send me which may make the Simples System better without increasing its complexity. As this is a very modest work, I would like to keep the license simple, compatible with the values of FLOSS, i.e. the Freedom of Users to have their systems behave the way they wish should outweigh the Freedom of Developers to have their creations operate as they imagine on other people’s systems!

GLOSSARY

Posix refers to a number of Operating Systems which follow much of the architecture of the Unix Timesharing System, including using Command Shells for configuration, customization and automation.

A Posix Operating System Consists Of

  • A UserLand running on top of a Kernel
  • The Userland
    • consisting of libraries, services, utilities and applications
    • which provide the functionality observed by users
  • Either a traditional Monolithic Kernel
    • A large and sophisticated software system
    • Running in a protected memory space
    • Interfaces with the physical Hardware of the machine
    • Provides a convenient and portable platform for the Userland
    • Not directly accessible to users
  • Or a Micro-Kernel with associated service daemons
    • Provides similar functionality to a Monolithic Kernel
    • Only a small part, the Micro-Kernel runs in a protected memory space
    • Possibly more secure and flexible
    • Possibly less performant and currently less popular

Posix-Compatible Operating Systems including

  • Unix
    • Developed at AT&T Bell Laboratories in the early 1970s
    • Required expensive licensing until after Gnu/Linux was developed
    • Not used much any more
  • the various BSD variants
    • Based on the Berkeley Software Distribution of the 1980s
    • Required expensive licensing until after Gnu/Linux was developed
    • Now consisting of many Open-Source projects
    • Usually includes many non-BSD additions
    • including FreeBSD, NetBSD, OpenBSD, Apple’s MacOS and IOS
  • Plan9 and Inferno
    • Developed at AT&T Bell Laboratories in the 1980s and 1990s
    • Awesome architectural innovations
    • Required expensive licensing until after Gnu/Linux was developed
    • Now open source, yet not much adopted
    • Some Plan9 components can be added onto other Operating Systems
      • Others are too tied to the Plan9 and Inferno architectures
  • Gnu/Linux
    • Started with the Gnu Project of the Free Software Foundation
    • Usually includes many non-Gnu additions
    • Runs on top of the Linux Kernel
    • Wildly popular, from portable devices to supercomputers
  • Gnu/Hurd
    • the GNU Userland
    • On top of the Hurd services running on a Micro-Kernel
    • Potentially more advanced, yet not yet mature

There are many Free Operating System Distributions!

Posix-Compatible Shells include

  • sh, ash, dash, ksh, bash, zsh
    • The /Gnu/Linux standard shell is bash
    • BSD users use various Posix-Compatible Shells
    • Apple has recently switched from (an ancient) bash to zsh
  • Microsoft provides bash for Posix Compatibility
    • Along with their new Powershell
    • And their old Command Prompt shell

DEVELOPMENT NOTES

Right now we’re in transition

  • Even more than usual!

Urgent Needs

  • Finish the transition!
  • Fix install-library and install-dotfiles to do what is required
    • And to test things!

We’re getting rid of the various “local” scripts in favor of

  • sh compatible scripts under ~/.profile.d/
    • sourced by the standard ~/.profile script
  • bash compatible scripts under ~/.bash_profile.d/
    • sourced by the standard ~/.bash_profile script

We’re moving a lot of functionality from bash to sh

  • where efficiency is similar
  • the bash scripts source the sh scripts
    • and maybe export the functions

The Bash-Simples code is staying

  • There’s probably no need for sh simples
  • But it would be nice to restore compatibility!
  • And to remove anything no longer needed
    • such as path setting, which is now purely sh code

Where users are able to get their Display Managers and Session Managers to use bash

  • Everything should work just the same
  • But with better performance
    • Less startup delay (not having to source as much)
    • Shell functions exported

About

BASH Profile Scripts and Simples Loadable Module System


Languages

Language:Shell 98.1%Language:Awk 1.6%Language:Makefile 0.3%