bash posts

Using pipes to augment IO of command with bash script

I like the interactive mode of the bc command line calculator because it is ubiquitous, but wanted to augment its functionality a bit to add a couple features I liked from another calculator program. I wanted to make modifications to the text I typed before sent to bc and modify the text it outputted. This can be done on standard POSIX shells with mkfifo, but it took me a good while to figure out how to do this with both input and output and get something working nicely without it freezing or leaving artifacts. So I’m sharing how to do this in a bash script.

Continue reading post "Using pipes to augment IO of command with bash script"

ls colors for both linux and bsd

ls can have nice colors enabled to differentiate between file types easily, but the parameter is different between the BSD version (uses --color) and the GNU Linux version (uses -G). I have been setting up a “bash_profile”, among other things, to be shared between my users on all the POSIX computers I use. Some are Linux, some BSD based. I use Bash on both, and I wanted the colors from ls to be used on both with the shared “bash_profile” file. I couldn’t find anyone else’s solution for this, so I figured one out myself and will post it in case others want the same versatility. I simply test ls with one of the parameters and see if it throws an error. I then can set my aliases with the appropriate parameter. I do it like so:

ls --color > /dev/null 2>&1
if [ $? -eq 0 ]; then
    alias l="ls -F --color"
    alias ll="ls -lh --color"
else
    alias l="ls -FG"
    alias ll="ls -lhG"
fi