8
1
I've got a rather extensive selection of dotfiles thats been kept in a git repo for the longest time - I just maintain a separate branch of code for bsd-isms (for instance, on Linux, to get colored ls output you do ls --color=auto
, but on BSD-likes including Mac OS, it's ls -g
).
This has started to become unwieldy since I have to make the change, then merge branches and deal with conflict resolution every time I touch my shell's rc file. Figure the proper way to handle this would be to drop the git branching, and just have my rc file determine what kind of OS its on, and then source an appropriate addon script for the aliases.
Problem is, I have no idea how to do this.
How do I tell if I'm on Linux or BSD from within a script or shell rc file?
uname
won't really work since then I have to write a bunch of logic for the various flavors of systems out there. Mac says Darwin, FreeBSD, etc, when I'm more interested in the underlying type of OS since that will impact what particular set of tools I'm dealing with. For my example above, am I using bsd ls
or GNU ls
?
isn't
uname -o
enough? ps: Osx has Darwin roots. – Lorenzo Von Matterhorn – 2013-09-24T16:16:40.6802
Have you seen this answer on Stack Overflow? It looks like exactly what you're after.
– John Bensin – 2013-09-24T16:20:44.0471-o is an illegal option on the
uname
that comes with Mac OS. See why this is such a problem? ;) – Mikey T.K. – 2013-09-24T16:20:53.467@JohnBensin That'll do! Could you make that an answer so the appropriate points are awarded? – Mikey T.K. – 2013-09-24T16:27:05.993
1Since question is still on topic here, there's no harm in it staying. But if someone wants to quote some of that SO answer, you have to link back and mention the author of the answer. And you probably don't need to quote the whole answer – random – 2013-09-24T16:41:50.063
1as for me, i wont link it inside a new answer and take points from someone else's work. as long as its added as a comment is fine by me. @random thank you for the detailed explanation on how to react. – Lorenzo Von Matterhorn – 2013-09-24T16:43:39.290
2@LorenzoVonMatterhorn I added it as a CW answer. Comments aren't guaranteed to stick around, as they're second-class citizens on SE sites. Also, since links to other SE sites don't show up in the Related or Linked sidebar, a link buried in a comment thread isn't necessarily easy for future visitors to find, especially if they're not familiar with SE sites. The question just looks unanswered. – John Bensin – 2013-09-24T18:45:45.343