-->
Adventures & experiences in contemporary technology
The primary job done by the touch command in UNIX or Linux is to update the time stamps on files. However, it also has another function: creating an empty text file where you are "touching" a file that doesn’t exist. This has its uses, particularly when you want to reduce the amount of pointing and clicking that you need to do or you want to generate a series of empty files in a shell script. Whatever you do with it is up to you.
Here’s an idea that I got for a post before I spent that torrid weekend with Windows that caused me to jump ship to Linux. The idea of having a UNIX command line while still remaining in Windows did appeal to me at the time and Cygwin seems to provide an intriguing way to do this. At its most basic, it is a set of DLL’s that allow you to run standard UNIX commands in a shell like what you see below. However, it is extensible with a good number of packages that you can choose to install. NEdit is just one that gets included and I think that I spied Apache too. The standard installation is a web-based affair with your downloading only the components that you need; it’s worth trawling through the possibilities while you’re at it.
Now that I am firmly ensconced in the world of Linux, this may be one possibility that I will park, for a while anyway. After all, I now do have the full power of the UNIX command line…
The Windows 2000 command line feels an austere primitive when compared with the wonders of the UNIX/Linux equivalent. Windows XP feels a little better and PowerShell is another animal altogether. With the latter pair, you do get file or folder autocompletion upon hitting the TAB key. What I didn’t realise until recently was that continued tabbed cycled through the possibilities; I was hitting it once and retyping when I got the wrong folder or file. I stand corrected. With the shell in Linux/UNIX, you can get a listing of possibilities when you hit TAB for the second time and the first time only gives you completion as far as it can go with certainty; you’ll never get to the wrong place but you may not get anywhere at all. This works for bash but not ksh88 as far as I can see. It’s interesting how you can take two different approaches in order to reach the same end.
The time hounoured syntax for a for loop in a UNIX script is what you see below and that is what works with the default shell in Sun’s Solaris UNIX operating system, ksh88.
for i in 1 2 3 4 5 6 7 8 9 10
do
if [[ -d dir$i ]]
then
:
else
mkdir dir$i
fi
done
There is a much nicer syntax supported syntax the advent of ksh93. It follows C language conventions found in all sorts of places like Java, Perl, PHP and so on. Here is an example:
for (( i=1; i<11; i++ ))
do
if [[ -d dir$i ]]
then
:
else
mkdir dir$i
fi
done
The Windows command has always been the poor relation of its UNIX equivalent and it seems that Microsoft released PowerShell in order to remedy this. It seems to offer scripting possibilities beyond what is already available in Windows and is a free download for XP and Vista. I haven’t got to exploring its potential yet but it is on the to do list.