Return to site

Is Mac Os Unix Based

broken image


Mac OS X is based on BSD UNIX, which is open source. Apple releases its open source fork of BSD as the Darwin operating system. The XNU kernel that Apple uses is its variant of the Mach kernel, which is an implementation of UNIX. Edit: Some corrections courtesy Quora User.

  1. Is Mac Unix Based
  2. Is Mac Os Unix Based

Why programmers & coders love Mac OS X: Unix command line The herd switched to OS X from rival operating systems over an extended period. And part of this (a big part, according to many. MacOS is a Unix-based operating system, developed and marketed by Apple Inc. It is designed to run on Macintosh computers, having been pre-installed on all Macs since 2002. Within the market of home computers, and by web usage, macOS is the second most widely used desktop OS after Windows. I'm at the new Apple store in Tysons Corner, VA and have been looking at the new MAC OS based on the UNIX kernel. It is really fabulous. A UNIX kernel with incredible MAC graphics and apps running on The UNIX and Linux Forums.

By Xah Lee. Date:

Someone wrote:

http://www.theregister.co.uk/content/35/23562.html

The meat of the article says that from about 300 email feedback from their fanning article on Mac OS X, a meagre 10% thinks Mac OS X is a improvement, and the rest don't.

If the internet-proclaimed journalists and online-proclaimed publishing houses have any import, then it follows that i am a member of the elite 10% in society. Whoopee!

For me, with my strong disgust of the clueless mac fanatics' drool of Aqua and all associated pretty-petty-fluff, and hatred for the Apple Public-Relations doused *Open Sourced* and *Unix-based* espoused by equally if not more clueless sea of unix-abiding dimwits, i do not see much good in Mac OS X, except that it should stop crashing every-other-day like its precedent.

First of all, there is the name. Mac OS X. What's with the eks? We learned from Apple's Marketing Department that X is really not X, but ten. When did Apple went backwater and started to use Roman Numerals? Upon further pondering, it became apparent that the X is there for the drama. Apart from being a outstanding letter in the shape of a cross, there's the tomfoolery aspect in the traditions of Unix, POSIX, Irix, HP-UX, AU/X, AIX, XENIX, Linux ending in a X to allude to being a 'Unix-family' OS.

I was not going to 'upgrade' to OS X till when i absolutely need to, if i didn't get too disgusted and hopped onto Windows 2000 or XP pro (which i'm not too willing for political reasons), but unfortunately a hard-disk failure in December made me pickup OS X along with a replacement hard drive, because my boot CD that came with my 1999 era G4 is a few years old. OS X comes with OS 9, so i thought i might as well upgrade now. It is a matter of time, like it or not.

I upgraded in early December 2001, and have used OS X for a month now. To my delight, i have far too many good things to report, contrary to some of these internet-proclaimed opinion-throwing a-dime-a-dozen journalists, despite the facts that i don't share Apple Fanatics's fanaticality and unix fanatics's moronicity, both of which are the marketing whir for OS X.

• I love the new GUI. Yeah, i have doubted it, i still adamantly hate many of the pretty-fluffs i've read such as the fantastically stupid traffic light system, the Genie effect, the movie-in-doc effect, the pretty-useless dizzying dock magnification, the exalted transparencies everywhere, and i don't give a fart about change-for-change's-sake the new Finder and dock-of-ways. I'm of the attitude that when it comes to user interface, functionality reigns supreme. There is no amount of prettiness that should make functionality a sacrifice. Apple's new UI, in my opinion, have trod upon this functionality-supreme creed of mine. However, now that i have used the machine for daily work over a month, i can only say that i find the new Finder and the Mac OS X ways more functional than the classical OS 9, that i was able to do things more quickly. I guess one thing that helped this perception is that now Mac OS DOESN'T CRASH ANYMORE! My golly, now i don't have to worry about the order i launch/quit apps, the memory fragmentation problem, the setting of memory for each app, the fear of system-freeze when opening a tad too many windows in IE or bumping into some java site, unplugging my portable firewire drive as soon as i'm done so it won't corrupt if my system suddenly freezes, slowing down myself in fear of giving the OS a fit. My golly, now i have the stability of Windows (NT) on the Mac! Better now then never. As for all the little pretty-useless UI things, they just made OS X hatefully beautiful, bugged me in principle but turned out not in practice.

• Mac OS X for me in general is faster. When OS X 10.1 came out in October or so, i shudder at the fact that Apple dropped support of machines that's just frigging 1+ years old by dropping DVD player ability in PCI-based G4s sold in 2000. But Apple released a new version of DVD player in December that fixed that, and i'm just in time to catch it. When i bought my Yikes G4 in 1999-12, i fancy the prospect that i could have a small window that plays DVD while i go about in my work. Alas t's wasn't so. The motion picture would freeze and skid. By my delightful surprise, Mac OS X came to the rescue. Now, i can actually have a little window playing motion picture in DVD, while i go about doing work on my machine if i wanted. The picture won't skip. I suppose this capability is in your behated Microsoft Windows for long, but finally it came to the rest of us. (one thing that i extremely value but still lacking on the Mac, is DVD screen capture.)

There are many other detail i find OS X much better than 9, but I guess the above two are main points contrary to those who grieves about OS X. I hate unix and Perl, but given that i'm a unix admin and a god-damn-good Perl programer for years, i secretly find it nice to be able to exercise my expertise to my advantage under OS X. All those gobbledygook ls cd vi sed awk perl mysql sh csh tcsh ksh make | || && < and excrement and friends are now under the control of my fingers of my home OS. All the utterly-stupid but never-the-less-already-there unix programs are now available for Mac if i wanted it. Even though i disapprove, at least i should be thankful that Mac OS X, in certain aspect, can be thought of and used like a unix.

I sense that Apple or mac community is dropping the X and calling it plainly 10.n. I'm glad for that too. I think, for all sensible purposes, it is not wrong to consider Mac OS X a unix, therefore i prefer for the X to stick by the literary-foolish tradition of ending in X. (after all, we should not despise tradition just for the sake of Think Different.) But on the other hand, i utterly find it alarming if Apple started to give the air that the future of Mac is the unix ways, therefore i find the dropping of X by Apple a big relief.

Of course, there are still bugs and problems. Many of which in Finder annoys me. I also find the disabilities of QuicKey in OS X a disappointment. On the whole, my experience is that OS 10.1 beats OS 9 by far.

If you have a question, put $5 at patreon and message me.

From OS X Scientific Computing

Revision as of 05:55, 28 June 2012 by Wgscott(Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Contents

  • 6Unix Shells on OS X
  • 7Some Useful Unix Links to Help You Get Started
  • 8Troubleshooting

Introduction

Scientific computing is typically carried out on computers equipped with the unix operating system. There are many varieties, or 'flavors,' of unix, including Irix, Solaris, BSD, GNU/Linux and so on, each of which has its own peculiarities in terms of file system structure and occasionally command syntax, but they all tend to be quite similar and function according to the same principles. The flavor of unix on Apple computers running Mac OS X is called Darwin, and it is closely related to BSD, from which it has evolved. Unlike Cygwin, a unix emulator that can be grafted onto the Microsoft Windows operating system, Darwin is the fundamental core of the Mac OS X operating system. The whole of Mac OS X is thus a superset of unix; the Aqua graphical user interface (GUI) of OS X provides an aesthetically pleasing and functionally elegant mechanism by which the user can control the computer via the underlying unix operating system using mouse clicks in application windows rather than typing cryptic unix commands.

The OS X Aqua GUI interface shields the naive and routine users, who are mainly concerned with running applications such as Microsoft Word, Adobe Photoshop and so on, from the complexity of the underlying unix operating system. It also provides an intuitive, elegant and simplified mechanism for carrying out complex system administrative tasks whose command-line equivalents are often obscure to all but the most seasoned unix veteran. But between these extremes lies the need for command-line access to carry out scientific (and other) computing tasks. Fortunately, Apple also provides easy access to the unix command line environment for users who require it.

Apple's OS X operating system does not simply provide access to unix commands. OS X is unix. This is an important point, because it entails that any operation carried out in the GUI interface in OS X can, at least in principle (and almost always in practice), be carried out on the unix command line. It may be incredibly cumbersome to do so, but it is almost always possible, an important point to consider when writing shell scripts to automate routine tasks.

The Filesystem Structure

Apple has a a filesystem structure rather different from what one finds with canonical unix systems. This section gives an overview of the main points.

You Need to Install X-Windows

Apple's native windowing system is not X11. Fortunately, it is easy to install X11 on OS X, so you can have the best of both worlds.

  • X11 page

The Terminal Application and Alternatives

OS X includes an application, Terminal.app, that provides unfettered command-line access to the entire unix underpinnings of the operating system. The Terminal application (the .app suffix on all applications is hidden from view in the GUI) may be found in the directory /Applications/Utilities. Its icon looks like (surprise) a terminal. In addition to the Terminal application that Apple provides with OS X, other options are available. iTerm.app is a free, third-party application that is similar to Terminal.app but has additional functionality, most notably tabbed windows. Similarly, xterm is provided with Apple's X11.app (see section [#xwindows_section 1.2]), and any other x-windows-based terminal program may also be installed, so a user who requires all the familiar functionality of xterm or its brethren need not compromise.


  • See also Editors for OS X

In order to create or to edit the contents of a unix (ascii) text file, you will need to use a text editing program. There are at least three types to choose from. The simplest and most ubiquitous are command-line editors, such as vi(m), pico and emacs, and those come with OS X. An enhanced user experience is made possible by editors augmented with a graphical user interface. These include X-windows based GUI editors such as gvim and xemacs, as well as true OS X native Aqua text editor applications such as the TextEdit.app that comes with OS X, as well as payware editors. It is a good idea to master one of the command-line editors (vim or emacs), as these are the most versitile and ubiquitous, and sometimes may be the only realistic possibility when editing files while logged in to a remote account. My personal favorite is vi(m), which has powerful, albeit cryptic, syntax, and is much more lightweight than emacs.

I've created a separate wiki section called Editors for OS X that goes into much more detail and has links to specific options.

Line endings differ for each of unix files, standard Mac files, and Windows files. It is critical to save text files with unix line endings if the files are to be used as input for unix programs. If, for example, you create a file in Microsoft Word (a bad idea) and save it as a text file, it will, by default, put non-unix line endings (carriage return special characters) in the file. A simple way to change all line endings into the proper unix form is to use perl, taking advantage of the regular expressions n for unix line endings and r for carriage returns. To convert a file with Mac line endings to unix line endings, use:

To change a file having DOS line endings to one with unix line endings, use:

When you start a unix terminal session, a program known as a unix shell command interpreter, or simply a shell, is immediately invoked. The shell accepts commands and prints responses; it is thus the primary means by which the user communicates with the unix operating system. Several unix shells are distributed with Mac OS X. These are tcsh, bash and zsh; ksh joins the family with 10.4.x. Each has its own syntax, but tcsh is fundamentally different from the others. (If you look at what shell programs are provided in the /bin directory, you will find, in addition to those listed, sh and csh. These are in fact the same binary files as bash and tcsh, respectively.) Here are a couple of simple but essential examples of how the syntax differs between (t)csh and the others:


Operationtcsh or csh syntaxzsh, bash, sh, ksh syntax
setting an environment variablesetenv EDITOR vimexport EDITOR=vim
making an alias alias calc ``open -a calculatoralias calc=``open -a calculator


The Default Unix Shell on OS X

You can see that the two sets of commands are incompatable. If you did a new or clean install of OS X version 10.3 or more recent, the default user shell is bash. Bash is essentially an enhanced and GNU freeware version of the original Bourne shell, sh. If you have previous experience with bash (it is often the default on GNU/Linux installations), this should make the OS X command-line experience rather familiar. But if you are unfamiliar with bash, I recommend switching your shell either to tcsh or to zsh, as both of these are more user-friendly. If you upgraded from, or are still using, OS X version 10.2.x, 10.1.x or 10.0.x, the default user shell will be tcsh. tcsh is an enhanced version of csh, the ``c-shell,' which is more user-friendly than the Bourne shell, but early implementations were buggy, and the programming syntax is peculiar, so it developed a somewhat undeserved bad reputation.

Properties of the OS X Unix Shells

Each of the shells has its unique properties. The original unix shell was sh, or the Bourne shell. Its syntax tended to be a bit cryptic and its behavior user-unfriendly. In addition to being the command-line user interface, the shell is designed to be a programming language in which one can write shell scripts that are interpreted rather than compiled. The Korn shell, ksh, was developed as an enhanced shell programming environment, and some user-friendly features were also incorporated. Its syntax is rather similar to, but richer than, sh. The C-shell implemented a different syntax, one that is apparently more natural to those who know the C programming language. Early implementations tended to be buggy, and unlike ksh and later versions of sh (and zsh), there is no way to define functions (or subroutines) in csh, making shell programming more difficult. tcsh is an enhanced (and corrected) version of csh, and is considerably more user-friendly, introducing command-line completions (enabling the user to hit the tab key to complete typing of uniquely specified commands) and syntactic improvements.

Bash is the GNU Free Software Foundation re-implementation of sh designed for the GNU/linux operating system but available for installation on any platform. Invoked with the command sh, it emulates the canonical sh faithfully, but invoked as bash, it provides many useful enhancements, both in terms of user-friendliness and programmability. It is, however, more terse and cryptic than tcsh and zsh. The Z-shell, zsh, combined the programming power and superior syntax of ksh with the best user-friendly aspects of tcsh, and then added many of its own enhancements, making it the most powerful and pleasant shell for user interaction and programming. A few of the essential unique features of each of these shells are listed in the table below.


ShellOriginComments
shThe original Bourne shellpresent on every unix system
kshThe original Korn shellricher shell programming environment than sh
cshThe original C-shellc-like syntax; early versions buggy
tcshEnhanced C-shelluser-friendly and less buggy csh implementation
bashThe GNU Bourne-again shellenhanced and free sh implementation
zshThe Z shellenhanced, user-friendly ksh-like shell



Many scientists who use unix probably have gotten used to csh or tcsh without ever giving much thought to what shell they are using, but if you find yourself suddenly using one of the other shells, the different syntax can be frustrating. If you are a long-time tcsh user, you may be uncomfortable with bash. Furthermore, many scientific programs seem to assume in their user documentation that you are a (t)csh user. I find bash as a user shell a bit uncomfortable, and prefer tcsh or zsh. I have in fact made zsh my default user shell. zsh is the most user-friendly of all the shells, as well as the most powerful. (It is an enhanced version of ksh, but with all the user-friendly functionality of tcsh plus lots of other great things like recursive globbing, remote file completions, a whole bunch of really useful functions that are included, etc.).

Is Mac Unix Based

Changing your Shell

If you want to return to being a tcsh user, or to become a zsh user, just type one of the following commands:

or


Creating Unix Shell Startup Files

When you open a Terminal or terminal-like application, it will invoke your default user shell. As the shell starts up, it looks for various system and user-created startup files that govern customizable settings for environment variables, the prompt, aliases, functions and so forth. What files are read depends upon which shell is invoked and which files are present. The user will need to create files in his or her home directory and include in them various commands in the appropriate syntax. Here is a listing of user shells along with what files will be read on startup. In several cases I have provided links to sample startup files (i.e., .bashrc, .bash_profile, .zshrc, .cshrc) to help get you started. These all include commands to set the DISPLAY variable properly and customizations for iTerm title bar and tab labels (these will also work for the title bar on Terminal.app and xterm). The files are commented to help you understand and change the customizable parts.


ShellUser filesComments
bash.bash_profile or .bashrc.bashrc for non-login and .bash_profile for login shells
ksh.profile or .kshrc.kshrc is always read
tcsh.login and .cshrc.cshrc is always read
zsh.zlogin and .zshrc and .zshenv.zshenv is always read; .zshrc almost always read



Bash is unusual in that the .bashrc is always read on an invocation of bash, except in the case of an interactive login, when .bash_profile is read (if present). This is further complicated by the fact that an 'su' command (switch user) is issued, such as su - (switching to root), the bash shell behaves as sh behaves for compatibility reasons and reads .profile from the root's home directory. Also, by default, the root user, if enabled, has it's shell set to sh. So if you use the root account, you should use cash to your favorite shell there as well. For the root user, you can create a .profile that sources your user's .bashrc and .bash_profile. Because a login shell is reads .bash_profile and because Apple's Terminal.app performs a login as it's first step, it reads .bash_profile. However, when xterm and related terminals are started on OS X, depending on whether they invoke a login shell or not, .bashrc may be read. This can create massive headaches for the user who uses both types of terminals interchangeably.1.11

The simplest and most robust solution to this problem is to do the following:

1. Put all of your bash customizations into your .bash_profile file.

2. Put the following line into your .bash_profile to force it to run your .bashrc every time the shell runs your .bash_profile:

3. In /var/root (if you use root), create a .profile that sources your .bashrc and .bash_profile with the full path.

If you are trying to debug this, use the command 'logger' with a text string which you will see in the Console. Never use echo in any profile in the event you want to login using ssh.


One other note on .bashrc -- if you use it to setup important environment variables or modify the path, you must source it explicitly with a full path in scripts that are called by the system, say from a crontab or launchctl.

For the other shells, it is usually easiest to simply put all of your shell customizations into your .xshrc file.

Is Mac Os Unix Based

The following example shows lines a bash, ksh or zsh user might include in his or her .bashrc or .kshrc or .zshrc file to set the DISPLAY environment variable. The first line tests to see if the DISPLAY environment variable has already been set. If it has not, then a value of :0.0 will be assigned to it and the value is exported.

For single individual zsh, ksh and bash users, we can use the following syntax:

For individual tcsh users (csh is tcsh on OS X), you should instead use the following syntax in your .cshrc file:


This works well for one user, but OS X permits multiple users to be logged on simultaneously via ``Fast User Switching.' A problem then arises for the second person to log in and start X11.app. Since DISPLAY=:0.0 for the first user, the second user most likely needs to have DISPLAY=:1.0, and the third user to start X11 most likely needs DISPLAY=:2.0 and so on. But what if the second user logs out before the fourth user logs in? We need a way to ensure that every user gets the correct DISPLAY variable set. If it is assigned the wrong number, launching X-windows based applications from Terminal.app and iTerm.app will fail. For that reason what I have put in the sample startup scripts (linked above in the table) is a bit more complex.

Why zsh Should Be the Default Shell on OS X

I've assembled a web page with the above title composed of a number of useful links to unix resources. It has become fairly popular, and I try to update it regularly. The main points are summarized below, with hypertext links in the pdf and html versions of this document. Readers of the printed document will find visiting the above website much easier than entering a bunch of links into a browser.

General Unix Links:

Unix tutorial for beginners
Unix for beginners by Gerard J. Kleywegt (written by an X-ray crystallographer). Comprehensive.
Unix for beginners by Ian Tickle (written by an X-ray crystallographer). Some Dos/unix conversions.
Unixhelp for Users Edinburgh Univ. (a bit more advanced)
A note about Unix Shells My page. (brief notes about [t]csh vs. sh-type shells).
Apple's Command Line Primer covers basic shell concepts, frequently used commands, environment variables, and running programs.

General Unix Books:

Learning the Unix Operating System, 5th ed. (good for the absolute beginner).
Using csh and tcsh (the next most basic book, but has a lot of useful stuff in it). tcsh was the default shell in Jaguar and is available in Panther. (Use chsh -s tcsh to switch back to it.)
Guide to zsh (A free, on-line, and extremely well-written pdf and html book on the best shell ever invented.)
From Bash to Z shell An excellent more advanced introductory book, written by the zsh folks, that gives a highly useful introduction to bash (the default shell in Panther and Tiger) and zsh (what should have been the default shell in Panther and Tiger).
Unix in a Nutshell (a useful reference).


Books and tutorials specific to Mac OS X Unix:

Mac OS X has brought the world of unix to a new set of users, and it has some non-canonical quirks. Here are some helpful books:

Mac OS X Unix Tutorial
Learning Unix for Mac OS X, 2nd Edition (Very basic treatment for an absolute beginner.)
Mac OS X for Unix Geeks (introduce OS X to unix-oriented folks).
Unix for Mac OS X: Visual QuickPro Guide -- a couple of chapers are on line here: Unix for Mac OS X

OS X Unleashed, 4th ed. (basic to advanced). A large, very comprehensive book with stuff for beginners and more seasoned folks.

Gary Kerbaugh's Picks: A Valuable Suggested Reading List for OS X Unix
Bash on Mac OS X: O'Reilly macdevcenter.com tutorial

Zsh on OS X (My propaganda and how-to page for using the best user shell ever invented on the best operating system ever invented).

Some customization suggestions:


Here are some OS X applications and hacks that I can't live without.
Here are some ways to make the terminal-finder interactions more integrated.
Configuring zsh on OS X is easy with these drop-in scripts that work 'out of the box.'


Shell Scripting and scripting languages:


Unix shell commands can be put together to make fairly elaborate programs that you execute from a file called a shell script. These programs do not need to be compiled and are generally pretty easy to read and modify for your own needs. Here are a few places to start:

Unix shell scripting
Mendel Cooper's Advanced Bash Scripting Guide (A definitive source for sh-type scripting.)
Python scripting tutorial
Python for Science

Terminal.app starts and immediately launches a unix command

Terminal sessions that perform preprogrammed functions can be saved and initiated when needed. Occasionally the user may do this inadvertently, with surprising results. By far the easiest way to deal with this is to reset the Terminal application's user preferences by deleting the file


in the user's home directory.

Terminal.app is really small

If Apple's terminal window is very small and can't be resized, make sure the Monaco font is enabled. Terminal needs Apple's Monaco font. If that font is disabled or missing, the Terminal window will be really small and unusable. Use Font Book to enable the ''Monaco Font'' in the All Fonts collection. If you have previously picked a different custom font for Terminal windows, enable that font, or select a different font.

Running X11 programs that require 256 colors or 8-bit display

Launching an X-windows based unix program fails

If you try to launch an X-windows based unix program and obtain an error of the form


or


Google sketchup mac os x. or


Mac os posix

then it is most likely that you forgot to start Apple's X11.app. You can launch it from the command line by issuing the command open -a X11, double-click on the application's icon in /Applications/Utilities, or simply add it to your ``Accounts' System Preferences ``Login Items'.

If you try to launch an X-windows based unix program and obtain an error of the form


and X11 is in fact running, it probably indicates that DISPLAY has been set incorrectly. This happens when multiple instances of X11 are running, at least one of which was started by someone else (using Fast User Switching) and they have set DISPLAY to :0.0. In that case, issue the command


If this returns, for example, the value :2.0, then set DISPLAY to :2.0.

If you try to launch an X-windows based unix program and obtain an error of the form Chrome 37 for mac.


(where a number is not specified) and X11 is in fact running, it probably indicates that the DISPLAY environment variable has not been set. Use the procedure above or enter the appropriate commands into your shell startup files as described in Section 1.5.4 and initiate a new shell session.

If you launch X11.app and your blood pressure goes up because an xterm immediately appears, you can copy the file /etc/X11/xinit/xinitrc to .xinitrc in your home directory and comment out or delete the line xterm & in that file.

The Apple OS X Bulletin Board

Apple maintains a bulletin board discussion forum website where many knowledgeable and helpful people congregate. I have learned quite a bit, and have received generous help with several problems, from the Apple unix forum.

Retrieved from 'http://scottlab.ucsc.edu/xtal/wiki/index.php/Unix_and_OS_X:_The_Absolute_Essentials'




broken image