Bash shell: Creating Preferences

In OS X I'm currently writing a bash script that requires writing to preference file. I may eventually want to share it with users on other Unix-like OSs and would like to accommodate for that possibility ahead of time.

Most OS X applications save preferences in xml-format plist files. These preferences can be easily created, written and read even from the command line using the Defaults tool. Conventionally the plist files are stored within the user's home folder in ~/Library/Preferences/

Is there a similar preference management mechanism common to GNU/Linux or to BSD? Is there also a standardized location for storing preferences files?

Nope, no such thing. Individual tools have their individual conventions. E.g. Gnome uses a similar mechanism but it's by no means widely supported outside of Gnome.

I suspected a much. However that leaves my second question still unanswered: when distributing scripts which require the writing of preferences and caching of data to be used by future iterations- what would would be the standard or even just the polite path to store such files?

Chapter 10 of The Art of Unix Programming: Chapter�10.�Configuration documents the historical legacy in quite some detail. I wish I could point you to something better for future-proofing your solution. Your options are basically either create a dependency on some sort of XML library (if you are writing C code) or a dedicated configuration parsing tool (is this Defaults tool available as a port to other platforms?); or simply fall back to a stone-age flat-file format, with all its quirks and complications.

On Ubuntu, apt-file search bin/defaults reports that the package gnustep-base-common includes a tool by this name. It sort of goes with something I meant to mention, but forgot; I guess the Mac tool is somehow descended from the NeXT toolbox. (Gnustep / OpenStep are an open-source reimplementation of the NextStep framework. See also GNUstep - Wikipedia, the free encyclopedia)

GNUstep defaults database looks like the Gnustep tool doesn't actually use XML at all, though.