For anyone who has to live with both UNIX and NT in their day-to-day lives, it can be some comfort to know that it is possible, with a little work, to make the two environments nearly the same with respect to certain tools. I have been on a quest to find tools and utilities that have been ported from UNIX over to NT. For some of us, the command line is not dead and we still enjoy -- and even require -- our familiar UNIX tools to make the NT "experience" more fulfilling (only geeks get excited about this stuff, right?). The emphasis in this article will be on the word "free" since you can get robust and complete tools sets from the Internet community with that special word (free) in mind.
First things first. Home is where the heart is...it's also the place to put all of your creative output. For example, on all my computers (UNIX or NT), I have a home directory (c:\home\khamsi on NT and /home/khamsi on UNIX), where everything I create goes. Excluded are files like Netscape bookmarks, application .ini files, etc. An environment variable, HOME, is then set to this string. This makes backups easier along with helping shells and utilities have a place to start or get their initialization files (e.g., .emacs, .bashrc).
Many repetitive and automated tasks can only be accomplished through the use of a command line and some shell scripting language. So far, I've seen almost every kind of UNIX shell ported to NT. These shells include: Korn subset (sh.exe, NT 4.0 Resource Kit), Korn with more stuff (ksh.exe, from MSK), C shell (csh.exe from Hamilton Laboratories, excellent support, but you pay for it, i.e., not free), tcsh--C shell with filename completion (tcsh.exe) and bash, aka Bourne Again SHell (bash.exe, from Cygnus Solutions). These are all good shells and vary in their approach to making the conversion to NT.
Which shell is the best? It may be a matter of personal taste, but bash is a superset of the Bourne shell and if you work on UNIX system, you will need to know Bourne to do administrator work. Why learn another shell like csh or tcsh when one shell like bash will do? bash has features such as: file/directory/command completion, command history (including Emacs key bindings), command "search", looping/branching/conditional control, process control, and the list goes on. For more details on bash, there is a great book called "Learning the bash Shell" by Cameron Newham and Bill Rosenblatt (O'Reilly & Assoc.) that is worth getting.
If you do decide to get into bash, here is a little script (that I got off the net) you can run to get your "home" directory set up (i.e., when bash starts up, the current directory will be your HOME dir:
@echo off set HOME=%1 if "%2"=="" start bash -login if not "%2"=="" start bash -login -c "%2 %3 %4 %5 %6 %7 %8 %9"
Call this program BashLogin.cmd, for example, and make a shortcut on your desktop to it. I placed it in a "bin" directory under my home. Open the properties of this shortcut and click on the "Shortcut" tab. In the "Target" field, enter:
c:\home\khamsi\bin\BashLogin.cmd /home/khamsi
(Replace c:\home\khamsi\bin with whatever directory the
files resides in and replace /home/khamsi with your home
dir.) If you place:
PS1="[\!]\w> "
in your ".bashrc" (bash initialization file) located in your home directory, you will then get a nice prompt when bash starts up that looks like:
[1]~>
where the number "1" is the command number and the "~" means you are in your home directory.
Striving towards commonality between UNIX and NT systems, you can keep one version of your ".bashrc" file and surround OS specific code with the following:
if [ $OSTYPE = "win32" ]; then
echo Running on Win32 system.
# NT code here
else
echo Running on some other system.
# Non-NT code here
fi
In bash, OSTYPE is a built-in variable. That can be pretty skippy.
On the connectivity side, Samba rules the free file sharing domain for NT machines accessing UNIX drives. The last time I tried commercial NFS clients and server for NT, I was sorely disappointed. That was two years ago and hopefully things have gotten better.
There is a free X Window server for NT that is available on the net, but after using it for a few hours, it became obvious that for prolonged connections, you really need an industrial strength program, like Exceed, from Hummingbird Communications.
I have seen a few telnet/rlogin servers for NT and have used rcmd.exe/rcmdsvc.exe from the NT Resource Kit. Folks, this stuff works, but only with the command line and performance can be less than stellar. As a result, I have a plea to Microsoft (assume humble begging position), "Please, please, please build remote login and distributed GUI capabilities in NT...all versions, not just NT server." (Resume normal engineering position...one hand on coffee mug, other sweating on keyboard.)
Though there is a web site that is devoted to GNU (GNU's Not UNIX) Emacs, it also is jam packed with other UNIX ported tools and utilities, along with links to other sites who focus on ported tools. It's an astonishing central point in your UNIX-gone-NT tool quest.
If you are a developer, are going to be a developer or even have a neighbor whose second cousin was a developer in a previous life, get to learn GNU Emacs. It may be a steep learning curve, but the pain and torture will pay off in the long run. Emacs has a developer in mind, also anyone who:
You get the picture. Now the Win32 implementation of Emacs is good enough to have one ".emacs" file (the initialization file) for both NT and UNIX. To make this work, I have placed the following lisp code in my ".emacs" file to handle differences in Operating Systems (OS):
(if (eq system-type 'windows-nt) ;; init for NT
(progn
;; NT specific lisp code here
)
(progn
;; Non-NT stuff here
)
)
As with any programming language, there are several ways to do this. A wonderful book on this subject is called "Writing GNU Emacs Extensions" by Bob Glickstein (O'Reilly & Assoc.), and I highly recommend it for anyone who wants to learn Emacs lisp to customize their Emacs environment.
As a developer, source code is subject to peer reviews and these reviews can include code written on different OSs. Our review process involves distribution of printed material for reviewers in advance. Often printing methods for UNIX and NT vary widely, so it became necessary to have commonly formatted printed text, through a common mechanism. Luckily, some nice UNIX tools have been ported to NT to facilitate a common way to generate these documents. I have recently picked "enscript" as my print utility of choice because 1) it has some nice formatting features and 2) it works under UNIX and NT. To get enscript to work under NT though, you need this little trick:
net use lpt1: \\YourServer\YourPrinter
entered from the command prompt. As a side note for bash users, you would have to enter
net use lpt1: \\\\YouServer\\YourPrinter
to escape the backslashes. The next logical thing to beg Microsoft for is to get rid of that irritating backslash. DOS is nearly dead...let's take the backslash directory separator with it.
Even if you are not a system admin, you can get a lot of mileage out of a scripting language like Perl for Win32. The NT Resource Kits comes with a version, but for the most up-to-date build, check the table below. Rexx also comes with the Resource Kit, but I would recommend Perl in most cases because of its widespread use and feature list.
There are times when you get uuencoded files and want to uudecode them, or visa versa. I found a pair of Perl scripts on the net that both these functions in very little code. They are listed below with some tweeks that I did:
#!c:/usr/local/perl/bin/perl -w # uuencode in Perl. # Copyright (C) 1995 Free Software Foundation, Inc. # François Pinard, 1995. # `perl uudecode.pl FILES' will decode all uuencoded files found in # all input FILES, stripping headers and other non uuencoded data. while (<>) { if (/^begin [0-7][0-7][0-7] ([^\n ]+)$/) { open (OUTPUT, ">$1") || die "Cannot create $1\n"; binmode OUTPUT; while (<>) { last if /^end$/; $block = unpack ("u", $_); print OUTPUT $block; } close OUTPUT; } } exit 0;
#!c:/usr/local/perl/bin/perl -w
#>>-------------------------------------------------------------------
# -*- Perl -*-
#
# Name: uuencode.pl
# Purpose: To perform the uuencode function.
# Usage: uuendode.pl FileToEncode
# It will create a file called "FileToEncode.uue" where FileToEncode is
# whatever the user enters for a filename.
#
# Copyright 1997, Sarir Khamsi
#
# $Id: UnixToolsForNt.html,v 1.2 2000/02/13 01:56:51 khamsi Exp $
#<<-------------------------------------------------------------------
die "Usage: $0 FileToEncode\n" if (!defined ($ARGV[0]));
open (OUTPUT, ">$ARGV[0].uue") or die "Can't open $ARGV[0].uue: $!\n";
open (INPUT, $ARGV[0]) or die "Can't open $ARGV[0]: $!\n";
binmode INPUT;
print OUTPUT "begin 644 $ARGV[0]\n";
print OUTPUT pack ("u", $bloc) while read (INPUT, $bloc, 45);
print OUTPUT "`\n";
print OUTPUT "end\n";
close (OUTPUT);
close (INPUT);
exit 0;
Many talented people have poured hours into filling some holes in NT, and bringing over their favorite UNIX tool. The result is quite positive for those of us who play both sides of the OS fence. The more common tools we have between systems, the more time we can spend trying to keep up with all the other new technology that keeps coming out.
| Bash & many other tools | http://www.cygnus.com/misc/gnu-win32 |
| C shell | http://www.hamiltonlabs.com |
| CVS (revision control) | http://www.cyclic.com |
| enscript | http://www.ngs.fi/mtr/genscript/windows-95-NT |
| GNU Emacs and many other UNIX ported tools | http://www.cs.washington.edu/homes/voelker/ntemacs.html |
| Korn shell | http://www.mks.com |
| Korn shell subset | Microsoft Windows NT Resource Kit |
| Perl 5 | http://www.ActiveState.com |
| tcsh | ftp://ftp.blarg.net/users/amol/tcsh |
| Tons o' UNIX ported tools | http://www.reedkotler.com |
| X Window server | http://www.microimages.com |