Hamilton LaboratoriesHamilton C shell 2012User guideLanguage reference


Oregon Coast

Previous | Next

The sample C programs and C shell scripts in the samples directory are meant to help you install or experiment with Hamilton C shell. Deliberately, they're relatively trivial. All were created assuming TABS=3.


Convert ASCII to EBCDIC using the tr utility.


A simple C program that prints out the *argv[] (argument) and *envp[] (environmental variable) arrays. Notice that wildcarding, variable substitutions, quoting and command substitutions are done before the C program is started. If you do a lot of wildcarding, you can create and pass very long parameter lists (up to 32K characters.) Try some of these commands:

% args "ho"w 'no'w
% args "$cwd" '$cwd'
% args * "*" '*'
% args `whereis more`
% args '`whereis more`'
% args * *\* *\*\* | more

Find the average numeric values in a list. If none of the elements are numeric, return 0.


Emulate the POSIX basename command to extract just the last component of a pathname, deleting any suffix, if specified.


A simple self-loading procedure that calculates the minimum bits required to represent the argument it's passed as a binary integer.


A simple C program that reads from Stdin, copying to Stdout, using the specified blocksize. This program can be useful to read or write tape devices that only support certain blocksizes.


Print the date n number of days forward or backward from a given date. If only the bump value is given, today's date is bumped.


A simple C shell script for converting between Celsius and Fahrenheit.


Print the date corresponding to a given Julian day.


A C shell script for printing out the calendar for any given month, highlighting the current date. If no date is given, this month's calendar is printed.


Instructions and examples on customizing the screen colors.


Force numeric strings with leading zeros to be treated as decimal numbers rather than as octal.


Print the number of days separating two dates. If only one date is given, the difference between it and today's date is returned.


Calculate the difference in hours and fractions of an hour between two times, given in hours and minutes.


Emulate the POSIX basename command to extract all but the last level of a pathname.


This C program writes out the environment it's passed in the form of setenv commands. If you're installing Hamilton C shell for the first time, dumpenv is a convenient way to snapshot the environmental variables you've been using with cmd.exe in a form you can append to your login.csh file.


Look for duplicate files anywhere in a directory tree.


Convert EBCDIC to ASCII using the tr utility.


A C shell script that calculates when Easter will occur in any given year. If no year is given, the current year is assumed.


A simple C shell script for converting between Fahrenheit to Celsius.


The simple factor C shell script shown in the User Guide. It's intended to show to show the use of recursion, expressions, and a self-loading procedure.


Another C shell script showing expression evaluation. This defines a number of routines for calculating financial conversion factors, e.g., from present to future value.


Search the INCLUDE directories for the specified header file.


Fixup source files to discard any extraneous tabs or spaces at the end of the lines, to ensure that all lines end properly with \r\n and to ensure that the timestamps can be exactly represented on a FAT or HPFS partition.


Calculate the Julian day number (number of days since January 1, 4713 B.C.) for any given date. If you don't give a date, it uses today's date.


Customize the screen colors for a laptop computer.


A simple C shell script showing how a "make" function might be written in the C shell language. This one rebuilds any .exe files in the current directory that are older than the corresponding .c file or any of the .h files.


Find the maximum numeric value out of a list. If none of the elements are numeric, return 0.


A simple C shell script that constructs a special checksum of a credit card number to tell if the card number is plausible or not. The checksum used is designed to catch transposed or incorrect digits. Try it on the cards in your wallet.


Test whether the first argument word appears somewhere in the list given by the second argument.


Test by case-insensitive comparison whether the first argument word appears somewhere in the list given by the second argument.


Find the minimum numeric value out of a list. If none of the elements are numeric, return 0.


A variation on the builtin echo command that prints its *argv[] (argument) list with quotes around each word it's passed and tells the total character count. Try these examples:

% myecho now     is the
% myecho "now     is" the
% myecho `ls`
% myecho `echo`
% myecho `echo hello`
% myecho * *\* *\*\* | more 

List all the files or directories in the current directory that do not occur in the specified directory.


Calculate the percentage change between an old value and a new value.


Calculate the U.S. first class postage required for a given weight in ounces.


Convert ordinary filenames to POSIX format.


A trivial C program that just prints, then exits with the return code value you pass it. You can use this routine to see how the status variable is set and also, how the ;, || and && statement connectors work. Try these examples:

% rcode
% calc status
% rcode 1
% calc status
% echo $status
% echo status
% rcode 2
% calc status
% rcode 0 || rcode 1
% rcode 1 || rcode 2
% rcode 0 && rcode 1
% rcode 1 && rcode 2
% rcode 0;  rcode 1
% rcode 1;  rcode 2

rcode also illustrates another aspect of return codes to consider: if you use C library stdio (as rcode.c does) and you exit with a non-zero return code, stdio thinks it was an error and discards anything in the stdio buffers. In the following example, stdio writes to the screen are unbuffered so it works; but pipes are buffered, so nothing gets written to it:

% rcode 1
% rcode 1 | more
--- End of file ---

If you're writing an application that uses return codes, you should remember to explicitly flush the buffers with stdio fflush() or use the kernel calls directly.


Emulate the Bourne Shell's read command, which reads a line of input, breaking it into words, which are then assigned, one-by-one, to the variables whose names are passed as arguments.


A script for attempting to reconnect any unavailable network resources.


A script for converting Bourne or Korn shell scripts into Hamilton C shell scripts using a set of sed scripts contained in the sh2csh directory.


A short C shell script that calculates and prints the cumulative size of any number of files or directories.


Split up a string into multiple lines, replacing each occurrence of the separator text with a line break, writing them to stdout.


Extract a timestamp from a file or directory in the format needed by touch.exe.


A C shell script that does numeric integration using the trapezoidal rule.


A C shell script that searches for occurrences of a simple string in all the files with a given extension anywhere in a directory tree.


Compare the frompath and topath directories, looking for differences, updating the topath directory as needed to make it an up-to-date copy.


Print the elapsed time the system has been up.


A simple set of functions for doing vector math in both rectangualar and polar coordinates.


Print the day of the week corresponding to any given date.


Figure out what will be run if a command is typed.


Customize the screen colors for a bright white window.


Print the Win32 message corresponding to a given error code.

Previous | Next

Getting started with Hamilton C shell

Hamilton C shell, as it first wakes up.

Getting started with Hamilton C shell

A first few commands.

You can set the screen colors to your taste.

You can set the screen colors to your taste.