The Department's Unix systems are connected to the campus fiber optic networks directly. Note that Unix is case sensitive and that most entries are in lower case. If your logon attempt is unsuccessful, check to be sure that your [Caps Lock] key is not depressed.
Logon Sequence:
If you are using a terminal: If connected to the fiber optic network 1. Type: hercules (or mercury) at the 1. Type: telnet hercules (or mercury) Develnet Request: prompt. from the system prompt.2. Enter your username at the login: prompt.
3. Enter your password at the password: prompt. Note that your password will not appear on the screen as you type it.
4. Enter the name of the terminal you are using at the TERM=(vt100) prompt. Most of the terminals on campus are vt100. If your terminal is vt100, just press [Return] at the prompt. Other terminal types are act4 and adm3a.
Example:
DevelNET V6.0.0
DATE: May 16 11:07:57 1994
SUB : 0/4/07/004
BAUD: 9600 bps
Request: hercules [Return] beep
Connected
Press RETURN to continue
RISC/os (hercules)
login: johndoe [Return]
password: [Return]
Last Login: Fri Apr 12 15:38:55 from DEC5KI.CS.UREGIN
RISC/os (UMIPS) 5.01 hercules
Copyright 1986-1992, MIPS Computer Systems
All rights Reserved
TERM=(vt100) [Return]
hercules[1]
To Logoff:
1. Enter logout [Return] at the system prompt to terminate your session with Unix.
Example:
hercules[1] logout [Return]
Logged out on: Mon May 16 11:22:34 CST 1994
session 1 -- disconnected from 142.003.200.090...Disconnected
[[CTRL] s] -- Stops the display on your terminal from scrolling.
[[CTRL] q] -- Starts the display on your terminal scrolling. Used to restart the display after a [ [CTRL] s] is used.
[[CTRL] c] -- Cancels the current line or process (command).
NOTE: Due to buffering on some UNIX systems these key sequences may not take affect immediately.
[[CTRL] d] -- Stands for EOF (end of file) or end of input.
[[CTRL] z] -- Causes the current process to be suspended.
Enter bg [Return] to resume processing in the background.
Enter fg [Return] to resume processing in the foreground.
The MIPS version of csh running on hercules and mercury also allows previous command lines to be brought back and edited.
[[CTRL] p] -- Causes the previous command on the command stack to be retrieved.
[[CTRL] n] -- Causes the next command on the command stack to be retrieved.
[[CTRL] w] -- Deletes the current line.
[[CTRL] b] -- Moves the cursor back one position in the command line.
[[CTRL] f] -- Moves the cursor forward one position in the command line.
[[CTRL] a] -- Moves the cursor to the start of the command line.
Two characters can be used as 'wildcards' under Unix.
* represents any group of characters
? represents any single character
For example, if you wanted to see all of the files with a "c" file type you could use the "ls" command (which lists file and directory names) in conjunction with the "*" wildcard. e.g. ls *.c
If you had a series of files, test1 test2 test3 ... , you could enter "ls test?" to see all filenames beginning with "test" and ending with any character.
A file or subdirectory in a directory is called a child of that directory. i.e: temp is a child of lee and lee is the parent of temp.
To access a file located in another directory or subdirectory, specify the pathname, which consists of the names of directories and subdirectories separated by slashes followed by the filename. For example, the pathname to the file called "junk" under the subdirectory "john" in the preceding example is /u1/john/junk.
The pwd (print working directory) shows the path to your current location in the file hierarchy.
Under Unix, there are special files beginning with a period (.) that do not normally appear in a directory listing. One example is the ".mailrc" file which is used by a mail facility. If you understand the use of this type of file you may edit it to modify the behavior of the program.
Some special characters can be used to designate directories.
/ system root directory
. current directory
.. next higher directory from current directory
~username username's home directory
~/ your own home directory
Any one of these special characters can be used in a pathname.
cd path is used to change directories.
mkdir path is used to create a directory in the current directory.
rmdir path is used to remove user-created directories.
Every program has three files open during execution
standard input (keyboard)
standard output (screen)
standard error (screen)
The default standard input/output/error files can be changed by I/O redirection. > changes the standard output, but error messages still appear on the screen.
Example. ls -l > listing
output from ls -l will be written to the file listing instead of the screen.
>& - changes standard output as well as standard error.
>> - changes the standard output file, but appends instead of overwriting
Example. ls -l >> listing
output from ls -l will be appended to the file listing
>>& - changes standard output as well as standard error, but appends instead of overwriting
< - changes the standard input.
Example. pgm < input-file
pgm will expect input from input-file instead of keyboard.
Sometimes we want to run a series of programs such that output of one program is input to the next program.
Example.
pgm1 > out1
pgm2 < out1 > out2
pgm3 < out2 > out3
This can be done by pipelining, using the pipeline character [ |) as follows
pgm1 | pgm 2 | pgm3 > out3
Output of pgm1 goes as an input to pgm2.
Output of pgm2 goes as an input to pgm3.
We didn't have to create intermediate files out1, out2.
By default the terminal has certain characteristics
stty all - reports all the characteristics of a terminal the command can be used to change the characteristics as well.
stty raw -input is unbuffered and unprocessed this feature is especially useful when instantaneous response to pressing a key is desired.
Example. (y/n)
This mode has some limitations in some instances. This mode does not recognize any special characters; it does not add carriage-return during echo.
stty cooked -this is the normal mode, it does all the input processing.
stty cbreak -inbetween the first two. It is useful when you may not want a completely raw mode but may want unbuffered input. Most of the special characters are still recognized.
Many Unix commands have options that you can specify. For example, the "ls" command has many options that affect the way it behaves. To specify one or more options, preceed the letter associated with its option with a minus sign.
Example: ls -la
l - option to produce a long listing (show protections, date, etc)
a - option to show all files, including hidden files (those starting with a ".")
cat file [file ..] displays (catenate) the contents of a file[s] on your terminal . cd path is used to change directories. cp file1 file2 is used to copy file1 into file2. ls lists the contents of a directory . mkdir path is used to make a new directory. mv file1 file2 is used to move (rename) a file. The mv command works the same way as the cp command except that the source file is deleted. pwd print working directory. Gives the path to your current location in the file hierarchy. rm filename is used to erase or remove file(s). After a file has been removed, it cannot be recovered. rmdir path is used to remove user-created directories
comm file1 file2 This command looks for lines common to two files and writes them out in three columns. The first column contains lines found only in file1 the second column contains lines found only in file2 the third column contains lines found in both files. If -n is usedthe indicated column is not printed. example: comm -23 wordlist /usr/dict/words would print column 3 (the words in wordlist not found in the dictionary) and not columns 1 or 2. compress file This command used LZC data compression techniques to compress files. An extension of .Z is appended to the filename. diff file1 file2 Reports the differences between the two files specified. du This command displays the amount of disk space used. If no arguments are use the size of each child directory is printed. If a file or directory is specified only its size will be printed. If only the total disk space is desired the -s option can be used. finger name This command is used to find out about other users on the system. grep This command is used to perform pattern matching searching within files, using strings and regular expressions.The default output format is: file:line_matching_pattern. See the man page to see this commands many very useful options and "REGULAR EXPRESSIONS" for the valid patterns. Example mercury[468]% grep main *.c unpack.c: * main unpack.c:EXPORT int main(argc, argv) unpack.c:EXPORT int main() mult.c:main() head file This command writes the top lines of a file to stdout. By default the top ten lines are written, this can be changed by using -n where n is the number of lines that are desired. man command This command is used to display manual information on commands. To use this command, enter: man [Return] Information about that particular command will appear on your terminal. If you do not know the exact command use the -k (keyword option). For example if you wanted to know how to change a password you could enter: man -k password [Return] A list of commands associated with the keyword and a brief description of those commands is displayed on your terminal. The entry of interest in this case would be: passwd - change login password To find out more about the command you would then enter: man passwd [Return] more file [file ..] Displays the contents of a file[s] on your terminal a page at a time. Press [Return] to advance a page. news Print information about changes and other events the system manager wants all users to read. tail file This command writes the bottom lines of a file to stdout. By default the last ten lines are written, this can be changed by using -n where n is the number of lines that are desired. talk user This command is used to communicate interactively with other users. To initiate this facility, enter: talk other_userid [Return] The screen will clear, then a line splitting the screen in two is drawn. Once the receiver answers, both users can "converse" by typing in messages until [[CTRL] C) is issued. Your messages will appear in the upper half of the screen; responses will be displayed in the lower half. uncompress file.Z This command used LZC data compression techniques to uncompress files. whatis key_word Same as man -k. See above. zcat file.Z This command used LZC data compression techniques to uncompress files and write them to stdout. This is faster than using uncompress and cat individually since it displays and uncompress concurrently. The uncompressed data is not written to the disk.
csh is the program that is usually run when a user first logs in. The shell accepts input from the users terminal, parses them in to commands and arguments then passes them to the operating system. This is the interactive use of csh, it can also be used non interactively as an interpreted programming language. The shell also provide some features that make the user interface more user friendly.
The shell called tcsh (the T-C Shell) is also available for use. It is a superset of the regular c shell, containing added functionality. To run tcsh after logging in, simply type tcsh at your prompt. To have it installed as your default shell, send an e-mail message to trouble requesting your default shell to be changed. For information on the tcsh, please refer to the man pages (ie. man tcsh [Return])
The C shell maintains a history of commands typed at the prompt. These commands can be retrieved to be executed again or they can be modified before they are executed.
!! Recall last command !n Recall command n from the history list !pattern Recall most recent command beginning with pattern !?pattern? Recall most recent command that contains pattern
For example enter: !20 to recall the twentieth command you had entered in the current login session. Entering !v will usually bring up vi with the last file you edited. This is useful if you are going back and forth between compiling and editing.
Sometimes it is desirable to modify a previous command before it is run again. For example you may want to correct a spelling error.
:e remove all but the extension :p print command without executing it :r remove the extension :s/old/new/ substitute the old string for the new string. :& repeat last substitutionExample:
hercules[530]% test.c
test.c: Permission denied.
hercules[531]% !!:r
test
Instead of:
mkdir ../src/assignment#1/C
cd ../src/assignment#1/C
type:
mkdir ../src/assignment#1/C
cd !*
Argument Extractors
Function Example 0 first word (command) which !!:0 n n+1 th argument cd !ls:1 ^ first argument cd !ls:^ $ last argument mv a.out !!$ n-m Range of argument cat !12:2-4 * wildcard. All argument cat !12:*
You can use your own aliases for complicated commands.
Example:
alias delete rm
Would allow delete to be used in place of rm
For more complicated commands such as:
pgm1 filename | pgm2 | pgm3
where filename is an argument which can change you use argument substitution. This the same as argument substitution used by the history facility.
Example:
alias pgm pgm1 \* | pgm2 | pgm3
Now when you type
pgm filename
it is equivalent to typing
pgm1 filename | pgm2 | pgm3
Because \* refers to all the arguments of pgm. The back slash (\) is require to tell csh to not perform file substitution on the asterisks (*).
Example. a.out < input > output &
You can reduce the priority of the process by using nice as:
nice a.out < input > output
A process can be suspended by typing [ CTRL [Z] ] while it is executing. To bring a suspended or background process into the foreground type fg. To put a suspended process into the background (i.e.: the process is run but the terminal is free) type: bg.
To find out what process you have in the background type ps. This will give you a list of the running processes, their status, and their process id number (pid). To stop a process use the kill command. This command uses the processes id number to terminate its execution.
Example: kill pid
These commands can be useful for editing large programs as follows:
(a) vi the file
(b) make changes
(c) write the file but don't quit
(c) type[ CTRL [Z] ]
(d) compile and run the program
(e) if it doesn't work, type "fg". You are right where you made the change.
(f) undo the change by typing the letter [u].
This file,which should contain valid csh commands, is executed by csh every time you login. It can be use to set up some default parameters or print information about the system ie: some people like putting news in their .login.
.logout
This file,which should contain valid csh commands, is executed by csh every time you logout. It can be use to clean things up or print information about the system ie: some people like to put fortune in their .logout.
.cshrc
This file,which should contain valid csh commands, is executed by csh every time you start a new csh. It can be use to up aliases, paths, etc. It is important to not put too much in this file (ie: more than 20 alias is not recommended) since it slows down the startup of each csh process.
A csh program can be run in one of three ways:
* As an argument to 'csh'
This starts up a csh process under the current csh to process the commands in the specified file. If this method is used the file does not have to be executable. Any commands executed in this manner do not affect the current shell, i.e. if the file contains an alias command this alias will not take affect in the parent shell.
Example:
csh myprog
* As an argument to 'source'
This uses the current csh process to process the commands in the specified file. If this method is used the file does not have to be executable. Commands in this file affect the parent shell, i.e. if this file contains alias commands they will be in effect even after the script has finished execution.
Example:
source myprog
* As a comment at the start of the file
This starts up a csh process under the current csh to process the commands in the specified file. If this method is used the file has to be executable. Any commands executed in this manner do not affect the current shell, i.e. if the file contains an alias command this alias will not take affect in the parent shell.
Example:
#! /bin/csh first line in the file
set Is used to declare a variable local to the shell it is declared in. A local variable is assumed to be non numeric. Set, with no arguments, displays all defined variables. setenv is used to declare a variable that is global to the shell parent shell and all the child shells. These variables are assumed to be non numeric. This command can therefore be used in csh programs to change variables (i.e.: the path) in the login shell. It can also be used to pass information between different instances of a csh program(s). Setenv with no arguments displays all globally defined variables unset is used to negate the declaration of a variable declared with set. unsetenv is used to negate the declaration of a variable declared with setenv. @ is used to assign numeric values to a variable. This command is used with numeric operators.Once a variable is declared it can be used by placing a dollar sign ($) in front of the variable name. A variable can exist with no contents, this is useful for flagging certain conditions.
example:
mercury[427]% set name = dean
mercury[428]% echo $name
dean
mercury[429]% set (Set by itself displays all defined variables)
argv ()
name dean
os RISCos
mercury[430]% set name
mercury[431]% echo $name
mercury[432]% unset name
mercury[433]% echo $name
name: Undefined variable.
Example:
mercury[436]% set classes = (cs100 cs170 cs210 cs230 cs250)
mercury[437]% echo $classes
cs100 cs170 cs210 cs230 cs250
mercury[438]% echo $classes[2]
cs170
mercury[439]% echo $classes[2-4]
cs170 cs210 cs230
+ addition - subtraction / division * multiplication % modulus
Example:
mercury[458]% set num = 1
mercury[459]% echo $num
1
mercury[460]% @ num = $num + 1
mercury[461]% echo $num
2
These operators are for performing comparisons; they return either a TRUE (non zero) or a FALSE (zero).
== equal != not equal < less than <= less than or equal > greater than >= greater than or equal || logical inclusive OR operator && logical inclusive AND operator
The logical operators perform operations on each bit in the operands and return the result.
| bitwise inclusive OR operator & bitwise inclusive AND operator ^ bitwise exclusive OR operator
Example
510 | 1210 = 01012 | 11002 = 11012 = 1310
510 | | 410 = 01012 | | 01002 = TRUE
<< bit wise shift left >> bit wise shift right
Example:
a = 1 << 4 gives 16
i.e.: 00012 << 01002 gives 10002
~ one's compliment ! logical negation
-n filename where n is one of:
d is the file a directory? e does the file exist? f is the file a plan file? o do I own the file? r do I have read access? w do I have write access? x do I have execute access? z is the file empty (0 bytes long)?
Example:
mercury[465]% if -e .cshrc echo "file exists"
file exists
Example:
foreach FILE (*.doc)
echo $FILE > manual
cat $FILE >manual
end
Example:
while ( `finger @hercules |fgrep $1|wc -w ` > 0)
echo $1 logged in
sleep 2
end
echo $1 logged out
if (expression) command
or
if (expr) then
commands
[else if (expr2) then
commands2]
else
commands3
endif
switch (string)
case pattern1:
commands
[breaksw]
case pattern2:
commands
[breaksw]
[default:
commands
[breaksw]]
endsw
example:
repeat 6 ls
echo "enter number of files"
set ans = $<
The following program recursively searchs through the directory tree using grep to perform text searches on each file. It first finds the compressed files, which it uncompresses before the search, then finds the uncompressed files.
#! /bin/csh
#
# performs a recursive text search
# usage: tsearch pattern
#
switch ( "$3")
# compressed files:
case "-r1":
# check to see if there is a match
if (`zcat $2 |fgrep $1| wc -w` > 0 ) then
# if their is print the filename
echo FILE: $2 :
# and matching lines
zcat $2 |fgrep $1
endif
breaksw
# uncompressed files:
case "-r2":
# if the file is a regular file search it
if (-f "$2") fgrep $1 $2 /dev/null
breaksw
# the inital process
default:
# find all the compressed files
echo "searching compressed files"
find . -name \*.Z -exec $0 $1 {} -r1 \;
echo ""
# find all other files
echo "searching uncompressed files"
find . -name \*\[\!".Z"] -exec $0 $1 {} -r2 \;
endsw
In this example the program calls itself recursively, the first time $3 should be empty so that the default procedure is run. When $3 is -r1 the file is treated as a compressed file, if $3 is -r2 a grep is performed directly.
NOTE: care should be used because not all functions treat regular expressions the same.
The rules governing regular expression are:
. A period (known as a wildcard character) matches any character except the newline character.Example: The pattern: .... will match any 4 characters in the reference string, except a newline character. ^ A caret (^) appearing at the beginning of a pattern requires that the reference string must start with the specified pattern. Example: The pattern ^efghi will match only those reference strings starting with efghi; thus, it will match either of the following: efghi efghijlk but not: abcefghi *An escaped caret, or a caret appearing elsewhere in the pattern, is treated as a non- special character $ A dollar sign ($) appearing at the end of a pattern requires that the pattern appear at the end of a reference string Example: The pattern efghi$ Will match either of the following: efghi abcdefghi but not: efghijkl *An escaped dollar sign, or a dollar sign appearing elsewhere, is treated as a regular character) [string] Matches any single character within the brackets. Example: The pattern [ab01] matches a single occurrence of a character from the set: a b 0 1 * The minus can be made non-special by placing it first or last within the square brackets. The characters '$', '*' and '.' are not special within square brackets. * To match a right bracket (]) in the list, put it first, as in: []ab01] [?-?] The minus (-) character is special within square brackets. It is used to define a range of ASCII characters to be matched. For example: The pattern [a-z]matches any lower case letter. The pattern [a0-9b] matches one of the characters: a b or a digit between 0 and 9, inclusive. *The minus can be made non-special by placing it first or last within the square brackets. [^string] The caret (^) has a special meaning if it is the first character in the series: the pattern will match any character other than one in the list. Example: The pattern [^abc] Will match any character except one of: a b c *A caret appearing anywhere but in the first position is treated as a regular character. ?* Match zero or more occurrences of the immediately preceding regular expression. Example: The pattern a* matches zero or more occurrences of the character: a The pattern [A-Z]* matches zero or more occurrences of the upper case alphabet.NOTE:
* In order to constrain a pattern to the entire reference pattern, use the construction: ^pattern$
* The '[]' operator provides an easy mechanism to obtain case insensitivity. For example, to match the word: hello regardless of case, use the pattern: [Hh][Ee][Ll][Ll][Oo]
Hercules provides undergraduate students with a Unix environment. Faculty members can request student accounts for a class. These accounts will deleted when the students has not enrolled on a computer science class for two consecutive semesters.
tbl/eqn/nroff text formatting programs
FORTRAN language compiler
C language compiler
Java language compiler
Lisp language interpreter and compiler
dbx symbolic debugger
lint C error detector
ed, vi, emacs editors
As of May, 2000, it is no longer possible to print directly from Unix to any of the printers in the CS Department laboratories. You must instead FTP your file(s) to a PC and print from there using Notepad or Word.
The regular Unix print commands are shown here simply for the sake of completeness. They are however not applicable in our CS labs any longer.
To print:
lpr -Pprinter_name file [Return] - print on the designated printer
To check the printer status:
lpq -Pprinter_name [Return] - reports on the status of the designated printer
lprm [Return] will remove your job from the printer queue. Refer to the man entry on lprm for details on how to designate which print job and which printer you wish the job removed from. i.e. man lprm [Return]
The DEC stations provide Computer Science graduate students and senior undergrads with a X windows workstation based facility for research, and senior class work.
tbl/eqn/nroff/troff text formatting programs
latex text formatting program
C language compiler
Pascal language compiler
ADA language compiler
ed, vi, emacs editors
dvips a program to convert Latex dvi files to postscript format
ghostview for previewing postscript files.
ispell interactive spell checker.
Line Printer Commands:
To print:
lpr -Pc135 file [Return] - print on the DEC writer printer in CL135
lpr -Pc135lp [Return] - print on the line printer in CL135
lpr -Pc115lp [Return] - print on the line printer in CL115
nroff file | lpr -Pc135[Return] - send nroff output to a printer in CL135
To check the printer status:
lpq -Pc135lp [Return] - reports on the status of the CL135 line printer
lpq -Pc115lp [Return] - reports on the status of the CL115 line printer
lprm [Return] will remove your job from a printer queue. Refer to the man entry on lprm for details on how to designate which print job and which printer you wish the job removed from. i.e. man lprm [Return]
Mercury provides Computer Science faculty and graduate students with a facility for research, laser printing, and inter-departmental electronic mail.
tbl/eqn/nroff/troff text formatting programs
latex text formatting program
FORTRAN language compiler
C language compiler
Lisp language interpreter and compiler
ed, vi, emacs editors
dvitps a program to convert Latex dvi files to postscript format
Mercury's laser printer is available only to Computer Science Department faculty and graduate students.
Laser Printer Commands:
enscript file [Return] - prints a text file
latex file [Return] - creates a formatted output file with a 'dvi' extension
dvips file | lpr -Pprinter [Return] - prints a .dvi file
ptroff file [Return] - send troff output to the laser printer
lpq -Pprinter [Return] - reports on the status of the laser printer
Line Printer Commands:
To print:
lpr -Pc135 file [Return] - print on the DEC writer printer in CL135
lpr -Pc135lp [Return] - print on the line printer in CL135
lpr -Pc115lp [Return] - print on the line printer in CL115
nroff file | lpr [Return] - send nroff output to the small printer in CL135
To check the printer status:
lpq -Pc135lp [Return] - reports on the status of the CL135 line printer
lpq -Pc115lp [Return] - reports on the status of the CL115 line printer
lprm [Return] will remove your job from a printer queue. Refer to the man entry on lprm for details on how to designate which print job and which printer you wish the job removed from. i.e. man lprm [Return]
To allow users to have the same password on each machine in computer science all passwords are distributed from Mercury. This means that when a user wants to change their password they don't have to change it on each machine. To change your password:
If you do not have an account on If you have an account on Mercury Mercury 1. Choose a password 2. Logon to 1. Choose a password 2. On Mercury mercury. This will put you in the type: passwd 2. Type our current password program. 2. Type your password at: Current password: 3. current password at: Current Type your new password at: New password: 3. Type your new password password (? for help): 4. Type your at: New password (? for help): 4. new password again at: New password Type your new password again at: New (again): password (again):Passwords are distributed every night (around midnight) so password changes do not take effect on machines other than mercury until the next day.
It is important that you choose a good password. It should be easy for YOU to remember but not obvious for someone else. For example: the name of the dog you had when you were five would be good, your telephone number would not be good.
The most common way people break into accounts in to use the information from finger (ie: full name, phone number, etc) the next most common way in to use the system dictionary. To avoid these problems the password program places some restrictions on your password.
* Must be no less than 6 characters long, but only the first 8 are significant.
* Can not matches anything in your UNIX account information, such as your login name or an item from your "finger" data entry.
* Can not be in the system's spelling dictionary - unless it has some uppercase letters other than the first character. For example, "Explain" would be rejected but "exPlain" would be accepted.
* Can not have 3 or more repeated characters - thus "aaa" would be rejected.
The "C" compiler, CC, is used to create an executable from a source file. CC creates a file (called a.out by default) that is executable.
CC [options] files.c ...
options:
-c Create only the object file not the executable.
-Dname[=def] Define a variable name to be used during compilation
-g include a symbol table for dbx. This is used for debugging.
-Idir look in dir for include files
-Llib include lib in the load (link) phase
-o name give the produced file a name instead of a.out
-systype system define the system type to use (ie bsd or sysV)
-E run the C pre-processor only print hte results to stdout.
Examples:
cc -o tst tst.c
-o tst - will name the executable file "tst" rather than the default a.out
cc -DDEBUG -o example1 *.c -L/usr/include/bsd -lm
-DDEBUG - will define a pre-processor label named DEBUG
-o example1 - will name the executable file "example1"
-L/usr/include/bsd - will search the bsd include files as well and the standard path
-lm -will include the math library along with the standard C library
make [-f makefile] [options] [names]
options:
-f file - use file instead of the default makefile
-n - No execute mode. Print commands but do not execute them
-s - Silent mode. Do not print the commands as they are executed
name - Is the name of the object to make
Form of the makefile:
target:dependent1 [, dependent2 [,.....]]
command line
Example:
example1: example.c example.h
cc -o example example.c -lm
The second line, the command line, is executed if either example.c or example.h are newer than example1.
The target, example1 (the executable file), is dependent on the two source files, example.c and example.h. If either source file has been changed since the exectuable was created, then the command line is executed.
SEE THE EXAMPLE IN 4.6.6
Lint is used to detect bugs, portability problems and other errors in C programs.
lint [option] files
Options:
-Dname[=def] Define a variable name to be used during compilation
-Idir look in dir for include files
-Llib use lib from /usr/lib/lint
-u ignore undefined functions and variables
-v ignore unused functions and variables
-x ignore unused functions referred to by external declarations
-z do not issue undefined structure messages
Dbx is a source code debugger for C, Pascal and FORTRAN. If a file is not specified the default file is a.out. If a core file is specified the information contained in it can be used to determine where a program crashed.
To use dbx effectively the program should be compiled with the -g option so that it contains a symbol table.
dbx [objfile [corefile]]
Cb reads C code from either the files specified or from standard input and writes code that has been reformated to standard out.
cb [options] [files]
-j Cause split lines to be put back together
-l length Split any line longer that length.
By default, line breaks are not changed.
tar -{rxtc}[of] [tapefile] file1 file2.
DESCRIPTION
tar (tape archive) saves and restores multiple files on a single file (usually a magnetic tape, but it can be any file). tar's actions are controlled by the first argument. The first argument is a string of characters containing at most one function letter and possibly one or more function modifiers. Other arguments to tar are file or directory names specifying which files to dump or restore. In all cases, appearance of a directory name refers to the files and (recursively) sub directories of that directory.
The function portion of the first argument is specified by one of the following :
r The named files are written on the end of the tape. The c function implies this. (NOTE: the r function will not write files on the end of most cartridge tapes, and even on some half-inch tapes. The nature of some devices makes it nearly impossible to seek back over individual records, so there is no way to find the end of the tar archive.)
x The named files are extracted from the tape. If the named file matches a directory whose contents had been written onto the tape, this directory is (recursively) extracted. The owner, modification time, and mode are restored (if possible). If no file argument is given, the entire content of the tape is extracted. Note that if multiple entries specifying the same file are on the tape, the last one overwrites all previous entries.
t The named files are listed each time they appear on the tape. If no file names are specified all the files in the archive are listed.
c Create a new tape; writing begins at the beginning of the tape instead of after the last file. This command implies r.
The following options may be used in addition to the desired function.
o On output, tar normally places information specifying owner and modes of directories in the archive. This modifier will suppress the directory information.
f Tar uses the next argument (tapefile) as the name of the archive instead of /dev/rmt?. If the name of the file is '-', tar writes to standard output or reads from standard input, whichever is appropriate.
#
# Filename: Makefile
# Written by: G. Dean Holroyd
# Date: April 28, 1992
#
# Purpose: This is a generic Makefile. Simply change the first
# section, type: make Depend to create a list of dependencies
# (ie: which source files use which headers), then use like
# normal (ie: make install)
#
#
# List all the c files a the object files #
OBJS = <-- insert
CFILES = <-- insert
#
# Give the executable file a name
NAME = <-- insert
# list any library files that might be needed
LIBS = <-- insert
#
# CPPFLAGS are used by the Depend: portion to find the include files
# for bsd under system V use:
CPPFLAGS = -I/usr/include/bsd
# for system V use:
# CPPFLAGS =
# define the c flags you want:
# use for compiling bsd on system V and the debug option:
CCFLAGS = -systype bsd43 -g
# use for system V and debug option:
#CCFLAGS = -g
######################################################################## # END OF THINGS THAT SHOULD BE CHANGED
######################################################################## # this line is needed for Depend to work
CC = cc ${CCFLAGS}
# makes the executable
${NAME}: ${OBJS}
${CC} -o ${NAME} ${OBJS} ${LIBS}
# used to run lint
lint:
lint ${CFILES}
# used to cleanup after a make
clean:
rm ${OBJS}
########### DO NOT ADD ANYTHING BELOW THIS LINE ! ***************
DEPENDFILES = $(CFILES)
Depend:
@ echo making dependencies
@ echo > makedep
@ cc -M $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEPENDFILES) > makedep
@ echo '/^# DO NOT DELETE THIS LINE/+2,$$d' > eddep
@ echo '$$r makedep' >> eddep
@ echo 'w Makefile' >> eddep
@ cp Makefile Makefile.bak
@ ed - Makefile < eddep
@ /bin/rm makedep eddep
@ echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
@ echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
@ echo '# see make depend above' >> Makefile
@ echo >> Makefile
@ echo '# END' >> Makefile
# DO NOT DELETE THIS LINE
# DEPENDENCIES MUST END AT END OF FILE
# DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# see make depend above
# END
Using the optimization flag will probably double your execution speed.
q16: q16.u ddeterm.u fdeterm.u
cc -O3 q16.u ddeterm.u fdeterm.u -o q16 -lm
q16.u: q16.c
cc -O2 -c q16.c -j
fdeterm.u: fdeterm.c
cc -O2 -c -float fdeterm.c -j
ddeterm.u: ddeterm.c
cc -O2 -c ddeterm.c -j
Tbl is a preprocessor used for defining tables within the troff text formatter program. Tbl commands, that define the start and end of a table and so forth, are placed within a file using a Unix editor. To view the formatted output on a terminal, enter the following command sequence:
tbl file | nroff | colcrt | more [Return]
The command sequence to send output to a printer device will depend on the specific implementation. Refer to the Mercury and Hercules sections of this chapter for details.
The general format for defining a table with tbl is:
options; instructions (separated by spaces) on how the whole table is to be formatted
format(s). instructions (separated by spaces) on how each line of the table is to be formatted
entry entry table entries separated by the [ Tab) character
.TE tbl macro to define the end of a table
expand - to make the table as wide as the line length
box - to enclose the table in a box
allbox - to enclose each table item in a box
r - to have the table entry right justified
c - to have the table entry centered
| - to have a vertical bar between table entries
center box;
l l.
item1 [Tab] description of item1
item2 [Tab] description of item2
.TE
item1 description of item1
item2 description of item2
Eqn is a preprocessor for used for defining equations within the troff text formatter program. Eqn commands, to define the start and end of an equation and so forth, are placed within a file using a Unix editor. To view the formatted output on a terminal enter the following command sequence:
eqn file | nroff | colcrt | more [Return]
The command sequence to send output to a printer device will depend on the specific implementation. Refer to the Mercury and Hercules sections of this chapter for details.
The general format for defining an equation with eqn is:
mathematical expression containing eqn keywords
.EN eqn macro to define the end of an equation
sup - indicates that the next item is a superscript
sqrt - indicates that the next item is to be placed under a square root sign
int - indicates that the next item is an integral
Extra spaces around items can be forced by adding tilde (~) characters.
A simple example of the eqn definition for a equation is:
x sup 2 ~ + ~ y sub k
.EN
x 2 + y k
nroff commands are placed within a file using a Unix editor. An nroff command is placed on a line by itself and begins with a period in column 1. To view the formatted output on a terminal enter the following command sequence:
nroff file | colcrt | more [Return]
The command sequence to send output to a printer device will depend on the specific implementation. Refer to the Mercury and Hercules sections of this chapter for details.
The general format for formatting a file with nroff is:
line(s) of text
.xx nroff command
line(s) of text
. . .
Some examples of nroff commands are:
.ce n center the next 'n' lines of text
.br break, i.e. begin a new line
.sp n leave a space of 'n' lines (spacing can be specified in inches or centimeters)
.ul n underline the next 'n' lines of text
Sample Heading line 1
Sample Heading line 1
.sp 1
This is a sentence.
This is another sentence.
Sample Heading line 1
Sample Heading line 1
This is a sentence. This is another sentence.
Although nroff has been used extensively in the past, it is likely that it will be replaced entirely with LaTeX.
LaTeX, a document preparation system, is an enhancement of the TeX typesetting program. LaTeX is designed to allow the user to concentrate on the overall structure of a document rather than being concerned with a great many formatting commands. In preparing a LaTeX input file it is important to understand the concept of environments. For example "article" and "book" environments perform automatic formatting of paragraphs whenever a blank line appears in the text. There are environments for formatting lists and mathematical expressions. The commands to define these environments are interspersed with text in a LaTeX input file.
You must run the input file (usually denoted by a .tex file extension) through LaTeX to produce a device independent file (denoted by a .dvi file extension) containing typesetting instructions. A second instruction is required to send the .dvi file to a printing device. Refer to the Mercury section of this manual for specific instructions on how to print.
The general form to define environments in a LaTeX input file is:
\begin [options]{environment}
text
text
\end{environment}
For example:
\begin {document}
A line of text.
Another line of text.
A line of text following a blank line will
become a new paragraph.
\end {document}
The formatted output of this file would appear as follows.
A line of text. Another line of text.
A line of text following a blank line will become a new paragraph.