Jan 30, 2015

Shebang, the Key to Portable Scripts


Although most Unix like operating systems these days have a port of the Bash shell, whether it is installed by default, where it is installed, and it's implementation does differ. For example, Linux installs Bash in /usr/bin where FreeBSD installs it in /usr/local/bin. When booting into Ubuntu, it may seem one is running Bash at first, but upon inspection one will notice that it is actually the Dash shell. The reason for changing to Dash can be found here.

To help improve compatibility across the growing number of OS' and distributions, a simple change can be applied. Enter the shebang! A shebang tells the OS what shell to use for the script by providing the absolute path to its executable, preceded by #! (shebang). As was mentioned above, the default path can vary depending on a few factors. There is a commonality among distributions which can eliminate this issue, and that is the env command. All this program does is look for the requested executable in all locations listed in $PATH. In other words, as long as bash is in one of the locations in $PATH, it will find it.  A shebang can also use env's absolute path instead of the shell's absolute path. All of the distributions I've looked at have env in the same location. So in conclusion, changing

#!/bin/bash

to

#!/usr/bin/env bash

 to your Bash shell script should solve most problems. An extremely simple solution to what may be a big headache otherwise.

Jan 29, 2015

Globally Enable UTF-8 (Unicode) on FreeBSD


One nice thing about FreeBSD is that it doesn't make many assumptions. This of course can lead to a bit of elbow grease being required, but at least the end result is an OS tailored to the need. One such instance is the lack of a set locale. A Google search produces quite a few results for setting locale on a per user basis, but setting locale globally is covered a little less.

First verify that locale is not set with:

$ locale


If no result is returned locale is not set. In order to set it /etc/login.conf must be modified as root. Open the file using your preferred editor and add the following lines:

:charset=UTF-8:\
:lang=en_US.UTF-8:


It is then necessary to update the system using:

# cap_mkdb /etc/login.conf
Logout and log back in. You should now see en_US.UTF-8 as follows:

$ locale
LANG=en_US.UTF-8
...

Jan 13, 2015

Google is NOT the new Microsoft

There are several places on the web that are stating Google is the new Microsoft.  Sure Google has become quite a large company.  Yes, Microsoft has improved their OS some and finally seen some benefit in open source software.  However, Google has quite a long way to go before it is able to fill the shoes Microsoft wears.  Those over sized, holed, heavy, uncomfortable shoes don't quite fit Google yet.

I digress, my intention is not another OS or search engine flame war.  My rants are usually based on something more substantial than preference of software licensing, or which CEO is better, or who has become too "corporate", or who is suing who.  So what inspired a new post after a few years of hiatus from I.T.?  An Excel spreadsheet.  A simple matter, but it hit the wrong buttons.  I simply wanted to keep an online copy of a timesheet made in Excel to have proof of the hours I worked.  Since it was in Excel I went ahead and used an old Microsoft account I had and put the spreadsheet on OneDrive.  Then I attempted to open that document in Excel Online.  Good thing I know from years of experience to test these things rather than wait until it's needed.  This was the result.



Well, that doesn't serve my purpose.  I decided to try Google Sheets and ...


Why on earth does Google Sheets handle an Excel workbook better than Excel Online!!!!!?????  And it's even an "unsupported" version of Chrome as can be seen by the info box in the pic.  There is one thing that was wrong in Google Sheets, and that is that this document is actually in landscape mode, but Google opened it in portrait mode.  Not a big deal.  I don't believe in extremes.  I don't hate everything Microsoft does because it has the Microsoft name on it.  And I don't love everything open source just because of it's openness.  I still use Microsoft Flight Simulator and it's Natural Ergonomic Keyboard ( I owned two of those at one point).  This is embarrassing though.  Shame on Microsoft and kudos to Google.

In the end it's one's own hardware and that means run the applications YOU prefer on whatever OS YOU think is best.  Issues like these sometimes don't leave much of a choice in the matter though.