What is the meaning of *nix, and what is its relation with Ruby?
Just saw that in an interview question... I think there is something to do with UNIX distros, but I am not sure.
Could not find it here or in the Wikipedia, so I am asking.
What is the meaning ?
And what is its relation with Ruby ? because the question was about Ruby.
*nix just means operating systems that are like the old workhorse Unix. Some examples include Linux, FreeBSD, and Mac OS X (its kernel, Darwin, is based on BSD).
The main relation between *nix and Ruby is just a pragmatic one; most Ruby developers seem to prefer to work on Unix-like OSes (typically Linux or Mac OS X). There's no official relationship, and it's quite possible to work with Ruby on non-*nix OSes like Windows.
*nix means UNIX-like; it is an operating system that behaves in a manner similar to that of a UNIX operating system without necessarily conforming to the Single UNIX Specification.
Wikipedia:*nix actually redirects to Wikipedia:Unix-like.
As for Ruby's connection to *nix, Ruby was developed mostly on GNU/Linux by the open-source community, so it may be something to do with Ruby running better on *nix systems or Ruby developers preferring to work on *nix systems.
It's an abbreviation for UNIX-like operating systems, including LINUX.
See also the UNIX-like Wikipedia page.
*nix is a general term to refer to the whole family of Unices, to the operating systems that follow the POSIX1 standard.
Ruby is a programming language, there's no general relationship between the two.
1: Portable Operating System Interface [for Unix]
It means the unix-like family of OSes. No relation to Ruby.
"*nix" refers to the Unix family of operating systems and its FOSS variants (Linux, FreeBSD, etc.). They have a different API than Windows, so any programming or scripting language that runs on them will have slightly different behavior and capabilities than on Windows.
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-like application is one that behaves like the corresponding Unix command or shell. There is no standard for defining the term, and some difference of opinion is possible as to the degree to which a given operating system or application is "Unix-like".
Related
I am writing several shell scripts using Ubuntu/bash and I would like to ensure that they are portable to OSX.
I have previously had trouble when I tried to use non-portable behavior of certain commands. Is there anything like an emulator for another shell environment?
I'm looking for an option besides just researching the portability of each command that I use.
Terminal.app is just a GUI, like xterm. It doesn't execute scripts. OS X uses bash, just like Ubuntu. It may, however, use a different version. For instance, OS X 10.9 uses bash version 3.2.51.
What you're describing is not Terminal and probably isn't bash. It's probably "the entirety of the command line tools that are installed by default." Things like grep, sed, and cut, and in practice you mean "the entire OS." There is no environment other than the OS that is going to capture all of those. Even if they did, you'd still need to worry about numerous other portability concerns like whether there is /proc filesystem (there isn't one on OS X).
Do you really mean to suggest that it only has to run on Ubuntu and OS X? FreeBSD is quite different. And there are many platforms that don't include all the GNU extensions that are common on Linux. In principle you could write to the POSIX standard, which they are all supposed to follow, but that won't really take you that far. In practice, the only way to know that you're portable to a platform is to test it on that platform.
But short version: no. You have to research first. And then you have to actually test it on each version of each platform you support.
There is another option though: don't use bash and don't use the low-level command line tools like grep. Use a higher-level language that you know will be on the target platform like Python, Perl, or Ruby. Then you just have to work to an old enough version of these languages and stay within the standard library. That's typically much easier to keep portable than bash scripts.
Whenever I write shell scripts (mostly software development utilities or build tools) I've generally tried to avoid using bash in favor of using plain old sh for portability. However lately I've been running into more and more issues where useful features are not available, or behavior is actually less consistent across systems using sh then it is using bash, since sh is aliased to different shells...
As I understand it, sh is the oldest Unix shell and carefully written sh scripts should in theory run on pretty much any system out there... but it also seems there are about 9000 different variants of every major shell, too. Doesn't using bash as your script interpreter effectively limit your script's portability? Sure, no problems on OS X or pretty much any Linux out there, but what about the BSDs? Solaris, AIX, HP-UX? What do you do if you really want to run on everything?
I know bash can be installed on virtually any OS but it is really a first class citizen on all relevant modern systems? Does it come pre-installed? I'm just not really sure whether it's best to avoid or embrace bash with the intent of having the most consistent and portable overall experience.
What do you do if you really want to run on everything?
You follow the POSIX standard for sh (and the tools you're calling) and hope that the target OS does so too. Any modern product called "UNIX" must follow this standard, and customarily (though not universally), the standard shell will be called /bin/sh. The BSDs and Linux distros tend to aim at POSIX compatibility as well.
Doesn't using bash as your script interpreter effectively limit your script's portability?
Yes, but it depends on your target audience as you noted. If it's a short script, it's worth testing under dash (Ubuntu and Debian's default shell) for POSIX compatibility.
Whenever I start thinking about portability issues in my shell script, I switch to another language. Perl is widely available and generally a good choice for scripts, but if your tools are to be consumed by Python, Ruby, $lang developers, use $lang to its full potential.
bash itself is just a plain C program, does not need special authority to run, can be put in any location. You can easily build it from source. Basically, you can run bash if you need to and doesn't need the administrator of the system to install it.
As long as it is in your path, you can always code your script with the line.
#!/usr/bin/env bash
I read that Mac OS X and bsd are related. How closely are they related. Can Mac OS X software be tweaked and installed on BSD?
Back in the days of OS X 10.4 I spent some time failing to write a VFS for OS X. In those days, of the major subsystems of the kernel, only the network stack and the VFS were still truly BSD. At that time, even the VFS had been partly rewritten to make it more modular (all the BSD VFS data structures became opaque pointers and the API was through what were called KPI functions). I believe the network stack was going the same way. There was also a thin layer at the interface with userland that made the OS look like BSD to userland programs.
Everything else had been pretty much rewritten or replaced: memory management, process management etc came from the Mach microkernel; the device driver subsystem was written from the ground up by Apple.
In terms of userland programming, OS X is very similar to BSD and programs written for BSD should be easily portable. However, OS X has a lot of APIs that aren't available in BSD. These include almost everything to do with the user interface - graphics, sound etc. There are also other interfaces that don't exist in BSD such as the launch API which is the OS X preferred way of launching background processes.
The Wikipedia BSD article is good (and accords with my own understanding, for what that's worth). It says that Darwin, the system on which Apple's Mac OS X is built, is a derivative of 4.4BSD-Lite2 and FreeBSD, and notes that 4.4BSD is the last release that Berkeley was involved with.
So, Darwin is as BSD as you can get (just like all the other BSDs!). OS X refers to those parts of the distribution which aren't open-source, principally the GUI, but including a variety of frameworks, and anything which relies on these won't be portable.
OS X as a whole is a UNIX 03 system. That's equivalent to being a truly POSIX-compliant system (as opposed to being POSIX-like).
As other answers have noted, the userland parts of the OS are unsurprising to anyone with much unix experience, and I've rarely had any difficulty building portable-unix software on OS X.
In contrast, the non-userland parts of the OS are pretty different. Apple seems to be willing to innovate in those areas fairly cheerfully. I think (but I'm not positive) that these changes are formally part of Darwin. One of the most obvious differences is that launchd has replaced cron, at, inetd, and much of the startup infrastructure.
If the Mac software uses Cocoa, Apple's proprietary display library (which it does, if it runs on the Mac with a GUI and does not require starting an X server), then you may have some issues running the code on a normal BSD system.
If your code only uses POSIX-specified functions, it will cleanly port to Linux, BSD, and even Windows.
It is true that Mac OS X and BSD are related. Although they have different kernels, they share a common ancestor and significant userland code. Obviously, I can't quantify "how close" - that's subjective.
Mac OS X is one flavor of BSD Unix. As Borelaid already pointed out, that does not necessarily mean that porting Mac apps to other flavors of BSD would be easy or even manageable, much less so than between other common BSD flavors. Every one of them brings their own specifics, and OS X more than most.
Porting programs from other BSD flavors to OS X also involves work and does not always work (smoothly or at all), but is usually much more straightforward.
It depends on what kinds of apps you are trying to port. If you write POSIX-compatible C/C++ console programs, they will compile and work just fine under any POSIX-compatible system (mostly Linux and BSD flavors), but note that OS X often doesn't implement the newest POSIX functions (e.g. utimensat) which are available in Linux. On the other hand, graphical applications use Cocoa or the older Carbon, which would require GNUstep. Porting graphical applications is quite uncommon because every graphical environment has different design standards and conventions, so graphical applications usually have to be written from scratch for each graphical environment.
Installed - no.
Ported from source, maybe - see Gnustep, Cocotron, EtoileOS - all of which offer varying degrees of compatibility with the Cocoa development stack (but not with the older Carbon).
There is a limited amount of x-platform objective-C software developed that way.
I know this question has kind-a started "religious" wars in past and there might not be one correct answer. But after working with ksh and csh for last 3-4 years and going through the pain of porting from one to another or applying a common piece of logic to multiple versions (read as legacy code), if I am writing a new script, I would go for ksh, but out of compulsion rather than choice. Is there a better option other than ksh/csh? Also something that is portable across Unixes (Solaris/HP/IBM/FreeBSD) and Linux (and if I am not asking too much or it if does make sense all Linux flavors)
Waiting for suggestions ...
Peace :)
Devang Kamdar
I would suggest plain old sh, which is available everywhere.
Also, it is worth noting that portability involves not only shell but also other commands used in a script such as awk, grep, ps or echo.
If you really want it to be portable (I don't know that any shell-script is maintainable), I would specify #!/bin/sh and test with dash and if possible other shells.
I would expect BASH to be the widest spread shell at the moment since it is the default for many Linux distributions (it can even run on Windows with cygwin, but that's probably true for the other shells, too).
An alternative might be to not use the shell itself for scripting but one of the scriping languages out there like perl, python, ruby, ...
I usually use ksh. I find that it's a good compromise between features and portability. It's there (or a compatible version is available) on most Linux boxes and Solaris. It's a while since I used HP-UX (thankfully) but I'm pretty sure it was available there too.
If all the machines you need to support are modern, bash might be an option. Solaris 10 comes with a copy. It's the default on most Linux machines.
Your lowest common denominator is going to be Bourne (sh), so that's worth considering if portability is your main concern. It's missing some of the more friendly features of ksh and bash though.
It's still worth steering clear of csh/tcsh for scripting. Csh Programming Considered Harmful is an oldie but still largely relevant.
My answer would be perl.
Does everything 'sh' 'bash' etc can do in a nicer more elegant manner.
Also it is actually more portable. A given version perl is very consistant accross all platforms. There are no significant differences between the Linux, Solaris and AIX distributions whereas porting shell scripts between these platforms is a real pain.
And it works on all windows paltforms! Provided you avoid backticks and "system()" your script has a good chance of running.
Python! Check out iPython, which is an enhanced Python interpreter. Also: Python for Unix and Linux System Adminitration.
You can write great portable scripts, and it's fun.
One of the bullet point features for Windows Vista Enterprize and Ultimate is the Unix subsystem for windows, which allows you to write posix... stuff? Anyway I'm outa my league talking about it... Anyone use this feature? Or explain it...
I know next to nothing about Unix programming.
It's probably best not to try to use the Posix subsystem for Windows. It was never really complete and is just a useless marketing tick box.
If you're truly interested in programming stuff for Unix, download one of the many Linux distributions (ie. Ubuntu) and VirtualBox. Install and start playing.
You might like Cygwin for having a Linux environment on your windows machine. Otherwise, definitely go for an isolated environment (virtual machines) like the others have suggested.
I don't want to discourage you from trying linux. But in this context it should be pointed out, that Linux is not completely posix compliant!
Wikipedia has a list of fully posix compliant operating systems
From that list, Solaris is probably the best to get started.
But anyway - for most of your posix-needs Linux should be the best choice (especially for beginners!)
The Posix subsystem in Windows is not only incomplete, but also slower in many cases than the "native" windows functions for the same thing. This is true for I/O for example.
In addition to Cygwin mentioned by another poster you should also consider MinGW.