unix, c programming, and (x)html · 2019. 10. 24. · unix-like systems: systems that work much...
TRANSCRIPT
![Page 1: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/1.jpg)
Unix, C Programming, and
(X)HTML
Instructor:
Dr. Cong-Cong Xing
![Page 2: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/2.jpg)
Access to Unix/Linux
Our Unix/Linux – (www.nicholls.edu)
telnet in MS Windows • Unsecured
• Not supported any more (by most Unix systems)
Putty – freeware, (telnet, ssh) • http://www.putty.nl/download.html
Login id and password • Id: ex: xing (lower case)
• Password: set it up (first time login)
Change your password • Type passwd at prompt
Exit Unix • Type: logout
![Page 3: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/3.jpg)
Introduction to Unix
Some useful terms: • Bit: a binary digit, either 0 or 1
• Byte: a grouping of 8 bits
• Kilo (K): thousand (≈10^3)
• Mega (M): million (≈ 10^6)
• Giga (G): billion (≈ 10^9)
• Hertz: used to measure clock speed. 1 hz = 1 pulse per second. 3 Ghz = 3 billion pulse per second.
![Page 4: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/4.jpg)
but in computing (esp. in terms
of storage)
symbol meaning roughly
Kilo K 210 (=1024) 103
Mega M 220 106
Giga G 230 109
Tera T 240 1012
Peta P 250 1015
![Page 5: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/5.jpg)
Ex: What is the max memory locations
(in terms of bytes) can a 32-bit CPU
address?
232 = 22 210 210 210 = 4GB
32-bit long register
memory
![Page 6: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/6.jpg)
• Flops: short for floating point operations per second. Also used to measure the speed of computers.
The origin of Unix (UNIX, officially) • Unix: The best OS people have written so far
• Dennis Ritchie and Ken Thompson from AT&T
• Multics – a failed OS, 1969
• GE, MIT, and AT&T (joint project)
![Page 7: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/7.jpg)
• Space Travel – a game
• Space Travel rewritten on PDP-7
• Unix was born in 1971
• Naming: Unics (a pun on Multics) Unix
• Turning Award (1983)
• http://awards.acm.org/homepage.cfm?srt=all&awd
=140
![Page 8: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/8.jpg)
![Page 9: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/9.jpg)
Unix and C
• Unix written initially in assembly language
(PDP series) (non-portable)
• In 1973, Unix was rewritten in C
• C was made for writing Unix
![Page 10: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/10.jpg)
Major Components of Unix
• Kernel: master control program. It manages
resources and handles multitasking.
• File System: organization of data.
• Shell: interface between users and kernel. It
interprets user commands and passes them
to kernel.
• Utilities: software tools built in Unix.
![Page 11: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/11.jpg)
kernel File sys
utilities shell user
![Page 12: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/12.jpg)
what is shell (programming)?
![Page 13: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/13.jpg)
Versions of Unix
• System V Unix ($): developed at AT&T.
AT&T Unix is the original Unix. Most Unix
systems on market are based on this. (e.g.
IBM AIX and Sun Solaris) (east coast)
• BSD Unix (%): modified at Berkeley and as
popular as AT&T Unix. (MacOS X is based on
BSD Unix) (west coast)
![Page 14: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/14.jpg)
• Unix-like systems: systems that work much like Unix,
but do not use any part of AT&T Unix. (e.g. Linux and
Minix)
X Window System (X11)
• A GUI for Unix, developed at MIT (1984)
• X terminals: a hybrid I/O device, has CPU and
memory and can run X but not a complete computer in
itself. (early days, when I was at grad school)
• X terminal emulator: software simulation of X terminals
• (Is windowing the original Microsoft’s idea?)
![Page 15: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/15.jpg)
Classic example of X window
![Page 16: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/16.jpg)
Example: Mac OS X
![Page 17: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/17.jpg)
X terminal in Mac OS X
![Page 18: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/18.jpg)
Books?
• Any introductory Unix book can help
• Or, any online tutorial
• Understanding Unix by Stan Kelly-Bootle
• Unix for Dummies by J.R. Levine and M.L.
Young
![Page 19: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/19.jpg)
Your Unix Account
The system administrator creates your account (and delete your account).
System administrator is the “super user” who can access any user’s account
Your account info: • Account name (id)
• Password
• Home directory
![Page 20: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/20.jpg)
• Group id: you may be assigned to a group of
users.
• Login shell
Terminals
• Called tty (abbr. for teletype) in Unix
• Putty (use telnet or ssh (recommend))
![Page 21: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/21.jpg)
![Page 22: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/22.jpg)
Getting Started
Use putty ssn or telent to login to eclipse
an old UNIX
server of our
dept.
![Page 23: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/23.jpg)
Login to eclipse.nicholls.edu
Successful login shows:
![Page 24: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/24.jpg)
login to web1.nicholls.edu
![Page 25: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/25.jpg)
Telnet to server
Use Window’s (old version) telnet to
login to eclipse
• Start Run telnet
• Type o
• Type host-name
• type your id and password at prompt
![Page 26: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/26.jpg)
Some useful commands
Shell prompt • $ -- Bourne shell, Korn shell, or bash shell
• % -- C shell or TC shell
• Will use $ throughout the slides
Script session, record whatever occurred • $script (to start a session)
• $exit (to end a session)
Password change • $ passwd
• Follow instructions
![Page 27: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/27.jpg)
Trying out some simple commands • $ date
Fri Jan 20 11:26:24 CST 2006
• $ w (check who is on the system)
11:30am up 116 day(s), 20:30, 3 users, load average: 1.92, 1.70, 1.67
User tty login@ idle JCPU PCPU what
xing pts/6 9:11am 27 -bash
xing pts/7 11:08am w
root pts/4 10Oct05 2days bash
![Page 28: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/28.jpg)
• $ whoami
• $ who
Email (built-in w/ Unix) • $ Mail <address> -- to send an email
• $ Mail -- to read emails
• Type x (or ^d or ^D) to quit reading emails
• Elm: a menu-driven e-mailer (not built-in, needs to be installed)
Unix manual • $ man <any command> -- manual page for the
command
![Page 29: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/29.jpg)
Logging out
• $ logout or
• $ exit or
• $ ^D
• One of the above has to work
Spelling
• Unix or UNIX? The latter is traditional, the
former acceptable
![Page 30: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/30.jpg)
Unix File System
File • Traditionally: a collection of related data
• Unix extends the traditional meaning of file
• To Unix, everything is a file (e.g., printer, disk drive, monitor, terminal, …)
File types • Ordinary files: common computer files
• Special files: device file, represent physical devices.
![Page 31: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/31.jpg)
• Directory files: ordinary files and special files
are organized into directory files or
directories.
Ordinary files divided into two groups
• Text files: (also called ASCII files) contains
text and created/modified by text editors.
• Binary files: containing non-textual data.
Read and processed by programs.
![Page 32: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/32.jpg)
Home and Working directories
• Home directory: the directory when you log in
the system.
• Each user has a unique home directory
• E.g.: /home/xing
• To go to home directory (from anywhere): $ cd
• Working directory: the current directory in
which you are working.
• Check what is your working directory: $ pwd
![Page 33: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/33.jpg)
Unix File Tree
• Files in Unix are organized in the form of a
tree, typically as:
bin dev etc home tmp usr var
Users’ home directories
Root (/)
![Page 34: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/34.jpg)
• Bin: short for “binary”. Contains shell software and common Unix commands
• Dev: short for “devices”. Holds device files.
• Etc: miscellaneous admin files (such as user list and passwords)
• Home: holds users’ home directories
• Tmp: temporary files are kept here.
• Usr: user-related files, on-line manual are kept here. home directories (for some version of Unix),
![Page 35: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/35.jpg)
• Var: holds files whose contents varies
frequently. Ex: users’ mail boxes are typically
in /var/mail directory
File Names
• 1 – 255 character long, combination of:
• A – Z
• a – z
• 0 – 9
• period (.), underscore (_), dash (-)
![Page 36: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/36.jpg)
• avoid using any special symbols and Unix
commands in file names.
Absolute pathnames
• full pathnames that identify the location of a
file in relation to root
• ex: (tree on next slide)
/home/al/cmps/hw1
/home/smith
![Page 37: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/37.jpg)
/
home
smith al
cmps math
hw1 hw2
![Page 38: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/38.jpg)
• ~ (tilde) represents the absolute pathname of
your home directory
• ~<username> represents the absolute
pathname of the home directory of that user
• three different ways to go back to your home:
• cd
• cd ~
• cd ~cxing
![Page 39: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/39.jpg)
what does this
possibly indicate?
![Page 40: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/40.jpg)
Relative pathnames
• relative to working directory
• . -- the current working directory
• .. -- parent of current working directory
• (Windows use the same thing)
![Page 41: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/41.jpg)
• ex: given the previous tree, assume you are
at /home/smith, then $cd ../al/cmps/ changes
to cmps directory
Listing files
• $ ls -- list all files in working directory
• $ ls ../al/cmps -- lists all files in
/home/al/cmps (assume pwd is /home/smith)
![Page 42: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/42.jpg)
Hidden Files and Directories
• a file or directory is hidden if it cannot be
listed by ls.
• $ ls -a -- to list all files and directories
Moving Files
• $ mv oldfilepathname newfilepathname
• ex: $ mv hw1 ../math/
( suppose at /home/al/cmps)
![Page 43: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/43.jpg)
Copying Files
• $ cp filepathname1 filepathname2
• ex: $ cp hw1 ../math/
$ cp ./hw1 ../math/
( suppose at /home/al/cmps)
Creating Files by Redirecting
• redirect from the “standard output”
• ex: $ ls > file1 -- result is saved in file1
![Page 44: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/44.jpg)
• note: redirection into an existing file overwrite
the file
• “double redirection” >> fixes the problem:
• $ ls >> file1 -- result is appended to file1
Links (hard, and symbolic)
• One file may have more than one name
• Each file has a unique i-node – an internal
data structure representing the location (disk
sector) of the file, the mode of the file,
![Page 45: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/45.jpg)
creation date & time, and other info.
• A (hard) link is a name that refers to a file’s i-
node.
• A link is created using the ln command
• Ex: $ ln existingfn newfn
• A symbolic link is a name that refers to
another (file) name.
• Ex: $ ln –s exitingfn newfn
![Page 46: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/46.jpg)
name1
name2
name3
name4
i-node
hard link to
name1
hard link to
name1
symbolic link to
name1
deletion of name1
will have no effect
on name2 (or 3), but
does affect name4
![Page 47: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/47.jpg)
ts.txt is a
symbolic
link to t.txt
after t.txt
is
removed,
the
symbolic
is “broken”
![Page 48: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/48.jpg)
the file dsf has
been removed.
dsf-link is ok,
but not dsf-s-
link
![Page 49: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/49.jpg)
Long Listing
• More info about files can be shown by
$ ls –l
drwxr-xr-x 2 xing staff 512 Jan 23 11:40 t
-rw-r--r-- 1 xing staff 8 Apr 26 2004 test
drwxr-xr-x 2 xing staff 512 Aug 24 00:06 test1
![Page 50: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/50.jpg)
drwxr-xr-x 2 xing staff 512 Jan 23 11:40 test
File
type
Access
control
links
(hard)
owner group Size
(byte)
Date &
time
name
![Page 51: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/51.jpg)
• File access control:
• First 3 symbols control what owner can do
• Next 3 symbols control what group can do
• Last 3 symbols control what public can do
• for first position: d means directory
- means file
l means (soft) link
• r (read) – examine (but not change) the contents of
a file
• w (write) – change the contents of a file
• x (execute) – run the file (program)
![Page 52: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/52.jpg)
• ex:
rwxrwx--- owner and group users have
read, write, and execute privileges,
public has no privileges
r--r--r-- everyone has read privilege only
changing file modes (1)
• u – user (owner)
• g – group
• o – others (public)
• a – all (owner, group, public)
![Page 53: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/53.jpg)
• = -- assign a permission (remove others)
• + -- add a permission
• - -- remove a permission
• ex:
• $ chmod u+x filename
add execution to user
• $ chmod g-rw filename remove read, write
permission from group
• $ chmod a=r filename
add read to everyone and remove anything else
• $ chmod u=rw,go=r filename (no space ..w,g…)
give user read and write, everyone else read
![Page 54: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/54.jpg)
changing file modes (2) • for each position, 1 indicates yes (permitted),
0 indicate no (not permitted)
• ex: r--r--r-- is denoted by 100100100
• break down into 3 parts and regards each part a binary number, and convert it to decimal
• then r--r--r-- can be denoted as 444
(1002=410)
![Page 55: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/55.jpg)
• more ex: rwxrwxrwx = 777
111 111 111
rwxr--r-- = 744
111 100 100
rw-rw---- = 660
110 110 000
--------- = 000
000 000 000
![Page 56: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/56.jpg)
chmod 777 filename
chmod 442 filename
![Page 57: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/57.jpg)
Conversion between binary and
decimal numbers
1112 = 1 × 22 + 1 × 21 + 1 × 20 = 710
1102 = 1 × 22 + 1 × 21 + 0 × 20 = 610
11102 = 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 1410
![Page 58: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/58.jpg)
6
2= 3 𝑟 0
3
2= 1 𝑟 1
1
2= 0 𝑟 1
610 = 1102
![Page 59: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/59.jpg)
14
2= 7 𝑟 0
7
2= 3 𝑟 1
3
2= 1 𝑟 1
1
2= 0 𝑟 1
1410 = 11102
proof that this conversion
scheme always works?
![Page 60: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/60.jpg)
Working with Files
Printing a calendar • $ cal
-- print current month
• $ cal month year
– prints the given month of the given year
-- ex: $ cal 12 2007
• $ cal year
-- prints the entire year
-- ex: $ cal 2006
![Page 61: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/61.jpg)
Viewing Files
• $ cat fname
-- (catenate) contents of a file (all the way to the end
of a file)
• $ more fname
-- display contents of a file (page by page)
-- type q to quit viewing
• $ less fname
• $ page fname
-- similar to more
![Page 62: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/62.jpg)
Concatenating Files
• $ cat file1 file2 ….
-- displays file1 followed by file2 …
• try/ex: $ cal 6 2007 > june-2006
$ cal 7 2007 > july-2006
$ cat june-2006 july-2007
$ cat june-2006 july-2007 > sum-2007
$ more sum-2007
![Page 63: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/63.jpg)
Appending to a File
• $ command >> fname
result produced by command is appended
to the end of fname
• try/ex: $ cal 8 2007 >> sum-2007
Deleting Files
• $ rm fname -- remove fname
Copying and Moving Files
• $ cp fn1 fn2 $ mv fn1 fn2 (see previous slides)
![Page 64: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/64.jpg)
Working with Directories
Creating a directory • $ mkdir dn --- creates a dir w/ name dn
• try/ex: $ mkdir cmps
$ ls
Removing a directory • $ rmdir dn --- remove the dir dn
Changing working directory • $ cd dn --- switch to dir dn
![Page 65: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/65.jpg)
Returning to the home directory
• $ cd or
• $ cd ~
Printing your working directory path
• $ pwd
![Page 66: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/66.jpg)
Unix common shells
name what when where who
Bourne shell
(sh)
Original
shell
1979 AT&T Steven Bourne
Korn shell
(ksh)
Improved
sh
1986 AT&T David Korn
Bourne again
shell (bash)
Improved
sh
1988 GNU project Brian Fox, Chet Ramey
C shell (csh) BSD Unix 1979 UC Berkely Bill Joy
TC shell (tcsh) Improved
csh
1980 CMU, Ohio
State
Ken Greer, Paul
Placeway
Debian
Almquist shell
(dash)
Decendant
Almquist
Shell (ash)
1977
(2002
rename)
BSD Kenneth Almquist
![Page 67: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/67.jpg)
Your login shell • Shown (maybe) at the command line prompt right
after login, if not
• Check what your login shell is
• $ ps
• Or, read contents of /etc/passwd
• Ex: $ grep cxing /etc/passwd
• Or, $ echo $SHELL
• Or, $ echo $0 (current shell)
• Set up by the administrator
![Page 68: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/68.jpg)
• To change your login shell: chsh
• $ more /etc/shells (to see available shells)
• $ chsh /bin/tcsh (to change to tcsh shell)
• $ chsh (follow instructions)
• $ chsh –s /bin/tcsh cxing (follow instructions,
change to tcsh shell)
![Page 69: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/69.jpg)
How Shell Processes Commands
Shell displays
prompt (e.g. $) –
ready to receive
commands
User types
A command
User types
return (end
of command)
shell interprets
the command
(looking for prog)
Kernel runs the
program and shell
“goes to sleep”
shell “wakes up”
when prog
finished. display
prompt again
![Page 70: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/70.jpg)
Options and Arguments
• options are switches that modify what a
command does.
• the fname that follows a command is referred
to as an argument.
• ex: $ ls -a -l fname or $ ls –al fname
check man for option info of a command
![Page 71: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/71.jpg)
• common options for ls
-a All files including hidden files
-l Long listing.
-F Flag the files. / after dir, * after exeutable
-r List files by reverse order
-h Sizes are scaled to be readable
-d List dir name (not its contents) when
argument is a dir, often used w/ -l to see the
status of a dir
![Page 72: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/72.jpg)
Standard input, output, and error
• (remember ) : everything is a file to Unix
• standard input: the file where programs look
for input. (keyboard by default)
• standard output: the file to which programs
send output. (monitor by default)
• standard error: the file to which programs
send error messages. (monitor by default)
![Page 73: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/73.jpg)
Redirection revisited • $ cal 2007 output is sent to standard
output – terminal monitor
• $ cal 2007 > cal.file standard output is redirected (to cal.file). output is sent to cal.file
• Mail xing input is taken from the standard input – keyboard
• Mail xing < afile standard input is redirected to afile. Input is taken from afile.
![Page 74: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/74.jpg)
Grouping commands
• c1; c2;... cn commands are executed one by
one consecutively.
• ex: $ w; ls; cal has the same effect as
$ w
$ ls
$ cal
• grouping can be useful in redirection
![Page 75: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/75.jpg)
• ex: create a calendar for summer of 2007
with grouping
$ (cal 6 2007; cal 7 2007; cal 8 2007) > sum2007
w/o grouping
?
![Page 76: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/76.jpg)
Piping • c1 | c2 connects the output from c1 to the
input of c2
• ex: $ cal 2007; cal 2008; cal 2009
(scrolls too fast)
$ (cal 2007; cal 2008; cal 2009) | more
(one screen at a time)
$ ls | more
the output of ls is connected to the input of more
![Page 77: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/77.jpg)
Tees
stdin
stdout file
tee file -- copies whatever in/from stdin to stdout, and to
file at the same time
![Page 78: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/78.jpg)
What entered w/
return (stdin)
(response to
input : stdin is
sent to stdout .
^d to finish)
the file ss has a copy of stdin
![Page 79: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/79.jpg)
command1
outfile command2
$ command1 | tee outfile | command2 (two pipes, one tee)
Output from command1 goes to file outfile and to stdin of command2
![Page 80: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/80.jpg)
• Ex:
$ (cal 2008; cal 2009) | tee mycal | more
Filters
• A filter refers to a utility which takes a stream
of data from stdin, transform the data in some
way, and sends the result to stdout
• Ex: cat, more, less, pg, wc, nl
![Page 81: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/81.jpg)
ex: nl – add line-numbers
cygwin – a Unix-
like environment
in Windows
![Page 82: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/82.jpg)
Wildcards
• Characters that can stand for other characters
• *, ?, []
• * -- stands for any sequence of symbols
• ? – stands for any single symbol
• [] – stands for any symbol included in the bracket
• Ex:
• ls *.exe
• ls *year*
![Page 83: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/83.jpg)
• ls temp?
• ls temp[abc]
• ls *[m-z]
• ls –ld *[m-z]
Quoting Special Characters
• Under some shells (e.g. csh), special attention need to
be made to echo special symbols
• ex: % echo What time is it?
% echo: No match.
![Page 84: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/84.jpg)
• to fix this problem
Quote Effect
\ Cancel the special meaning of next character
‘xxxx’ Cancel the special meaning of xxxx
“xxxx” Similar to ‘xxxx’, except for $, ``,and \
`xxxx` Execute the command xxxx
![Page 85: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/85.jpg)
Ex:
• $ echo what time is it\?
• What time is it?
• $ echo what time is it`date`
• what time is itMon Aug 13 ……
![Page 86: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/86.jpg)
Background processing • Under Unix, a process can run in foreground or
background.
• To run a process in background
$ command &
ex: $ sleep 60 & (sleep 60 seconds)
[1] 1865
where: [1] --- job #
1865 --- process id (PID)
• At command line, ^c to terminate process, ^z to suspend a process.
![Page 87: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/87.jpg)
![Page 88: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/88.jpg)
• To terminate a process:
$ kill pid kill -9 pid surely kill
$ kill %n (n is the job #) kill -9 %n surely kill
• some useful commands
bg %n send process n to background
fg %n bring process n to foreground
jobs list jobs status
kill %n terminate process n
stop %n suspend process n
ps show status of all processes
note: some commands may only work under certain shells
![Page 89: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/89.jpg)
Summary of job controls
Fg running
process
Suspended
process
Bg running
process
To bring it to
foreground
Nothing Fg it Fg it
To send it to
background
Suspend it
and bg it
Bg it Nothing
To Terminate ^c or
^z then kill it
Kill (-9) it kill (-9) it
To suspend ^z Nothing stop it(pid)
![Page 90: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/90.jpg)
bring a foreground process to background
![Page 91: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/91.jpg)
bring a background process to foreground
![Page 92: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/92.jpg)
History and filename completion
• $ history lists recently typed commands
• $ !# To re-run a command, # is the
number
• $ !! to re-run last command
• Trick
• Under csh, tcsh, bash, filenames can automatically
be completed by hitting the tab key
![Page 93: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/93.jpg)
To check your login shell • ps or
• echo $SHELL or
• echo $shell
To leave a shell • $ exit or $ logout
ftp and telnet (or ssh) • built-in Unix utilities
• telnet (or ssh): remote login to a networked computer
• ftp (sftp): file transfer protocol
• $ telnet hostname
![Page 94: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/94.jpg)
• $ ftp (sftp) id@hostname [-port]
• get – download files
• put – upload files
• ascii – set to ascii transfer mode
• binary – set to binary transfer mode
• bye (or quit) – to end ftp
• MS Windows
• ftp and telnet also exist in (old) MS Windows
• they work similarly as in Unix
![Page 95: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/95.jpg)
• for ftp, an easier way may be to use the GUI
program, e.g.:
• free software WinSCP, filezilla
• open My Computer | type hostname in the address
bar
• open a web browser, type the hostname in the
URL bar
![Page 96: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/96.jpg)
Free FTP software
• WinSCP
• https://winscp.net/eng/download.php
• filezilla
• https://filezilla-project.org/
![Page 97: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/97.jpg)
WinSCP
![Page 98: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/98.jpg)
Free Unix shell account?
![Page 99: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/99.jpg)
Free Unix account: sdf.org
![Page 100: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/100.jpg)
Command Summary
echo $SHELL or echo $shell check login shell
shellfile run shell specified in shellfile
exit exit a subsell
!n repeat nth command
!! repeat last command
fil <tab> complete file name starting w/ fil
^c kill a foreground process
^z suspend a foreground process
![Page 101: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/101.jpg)
bg %n send job n to background
fg %n bring job n to foreground
jobs list status of all jobs
kill pid kill process w/ id being pid
kill %n kill job n
kill -9 %n definitely kill job ns
stop %n suspend background job n
wc file count lines, words, and characters in file
![Page 102: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/102.jpg)
sort file sort lines of file in usual order
sleep n sleep n seconds
command & running in background
ps obtain process status
mkidr dir make directory
mv fi dir move file fi to directory dir
cd dir change to directory dir
cd change to home directory
![Page 103: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/103.jpg)
rmdir dir delete directory
pwd print working directory path
cal m yr show calendar for month m in year yr
cal yr show calendar for year yr
ls list files in working directory
cat fi show contents of file fi
more fi show contents of file fi, one screen at a time
pg fi similar to more
![Page 104: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/104.jpg)
cp fi1 fi2 copy file fi1 to file fi2
mv fi1 fil2 move file1 to asked
rm fi delete file fi
chmod spec fi change permission status of file fi
passwd change your password
date print current date
w check who is on the system
man comm check the manual for command comm
![Page 105: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/105.jpg)
logout logout system
exit logout system
^d logout system
(s)ftp File transfer (upload and download)
telnet remote login
ssh Secure remote login
![Page 106: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/106.jpg)
Example of real-world state-of-
the-art research (NFV-SONATA)
![Page 107: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/107.jpg)
Text Editor – Vi (or Vim)
To invoke vi
• $ vi fname
Unix shell
Command
mode
Insert mode
vi fname
i, o esc
:x
![Page 108: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/108.jpg)
Basic commands
• i ---- go to insert mode
• esc --- go to command mode
• h --- move left
• j --- move down
• k --- move up
• l --- move right
• o --- go to insert mode, move to next line
![Page 109: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/109.jpg)
Why choose “i”, “h”, “j” ,“k”,
“l”,.... ? ---Nearby finger tips
Left index
finger
right index
finger
![Page 110: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/110.jpg)
• x ---- delete one character
• dd --- delete entire line
• 0 (zero) – move cursor to the start of a line
• $ -- move the cursor to the end of a line
• u --- undo most recent change
• :q! --- quit w/o saving
• :x --- quit w/ saving
![Page 111: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/111.jpg)
More commands • :w --- save file w/o quitting
• a --- append text, go to insert mode
• J --- join current line w/ the next line together
• :w fname --- save file to fname
• “copy & paste” – yank and put • (do the following in command mode)
• ma (at the beginning of block, mark)
• y'a (at the end of block, yank)
• p (put what being yanked, put)
![Page 112: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/112.jpg)
Spell checking (may be unavailable…)
• $ spell fname
• $ ispell fname
Search
• :/ pattern --- find occurrence of pattern
• :/ <return> --- repeat last find
• :? pattern --- works like /, but backwards
• :? <return> --- works like /, but backwards
![Page 113: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/113.jpg)
global substitution
• :%s/old/new/g --- replace every occurrence of
old by new in the file
Number line
• :set nu :set nonu
Jumping around
• nG --- jump to nth line
• G --- jump to bottom
![Page 114: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/114.jpg)
command line editing using vi
• % bindkey –v (tcsh shell)
• $ set –o vi (bash )
• ex:
• $ echo I havee mad a mistake
press <esc> to enter vi mode move the cursor to
“havee” to fix it
press <return> to execute the command
![Page 115: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/115.jpg)
Networking
Terms • LAN – Local Area Network
• WAN – Wide Area Network
• Unix was designed to be a network-oriented OS (back in what year?)
Network Topology • Bus
• Ring
• Star
![Page 116: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/116.jpg)
bus
ring
star
hub
![Page 117: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/117.jpg)
Internet History
• (see http://en.wikipedia.org/wiki/Internet)
Internet Protocols
• Protocols --- data communication rules
• TCP – Transmission Control Protocol
• IP – Internet Protocol
• PPP --- point-to-point protocol
• SLIP – serial line internet protocol
High speed
Low speed
![Page 118: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/118.jpg)
IP Address and Domain Name
• IP address: four numbers separated by “.”
• Each host on the Internet has a unique IP
• ex: 128.46.126.96
• Each host can also be identified by its domain
name
• Ex: juno.eecs.tulane.edu
host subnet
organization
Top-level
domain
![Page 119: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/119.jpg)
• Common top-level domains • com – commercial organization
• edu -- school
• gov -- government
• mil -- military
• org – nonprofit organization
• net – network support organization
• Country names • ca – Canada ch -- Switzerland
• cn – China fr -- France
![Page 120: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/120.jpg)
E-mail (built-in in Unix)
• mail – original
• Mail – Berkeley mail
• mailx – System V mail
• elm – alternative to standard Unix mailers
• pine – similar to elm
Check to see if one has read his mail
• finger userid
![Page 121: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/121.jpg)
• ex: finger xing
Common Mail Conventions • :-) -- smile
• ;-) -- wink
• :-( -- frown
(26) xing@eclipse> finger xing
Login name: xing
Directory: /home/xing Shell: /bin/tcsh
On since Feb 17 05:49:55 on pts/2 from ip68-11-69-123.no.no.cox.net
New mail received Thu Feb 16 11:47:38 2006;
unread since Tue Feb 14 15:20:30 2006
![Page 122: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/122.jpg)
Classic Unix Network Utilities
• rlogin -- remote login
• telnet – remote login
• ftp – file transfer (protocol)
• rcp -- remote copy
Basic ftp commands (putty has sftp – psftp)
• ? (or help) -- for help
• ascii – for ASCII file transfer
• binary – for binary file transfer
![Page 123: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/123.jpg)
• put fn --- upload file fn (send)
• get fn – download file fn
• mget fn – multiple get
• other Unix commands also work under ftp , such as
• cd, pwd, ls
• Anonymous ftp (public ftp)
• Loign name: anonymous or guest
• Password: none
• Ex: ftp.census.gov
ftp.cac.psu.edu
![Page 124: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/124.jpg)
A problem with ftping files between
Windows and Unix.
• Windows text files (say, generated by
Notepad) will show ^M or ^[ at the end of each
line when displayed in Unix.
• How to fix it? Type the following
• tr –d ‘\015’ < inputFile > outFile
Octal for ^M
CR (carriage return) Input file name Output file
name
‘\015’ can be
replaced by ‘\033’
(octal for ^[ (ESC))
![Page 125: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/125.jpg)
![Page 126: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/126.jpg)
• How to find octal for other control characters?
• In vi insert mode, type <ctrl-v>, then type the
<ctrl-character>, then save the file (as fileName).
• Then, at the command line, type the following to
see the octal
• od –b fileName ( option –a to see name, not otcal)
• http://www.neurophys.wisc.edu/comp/docs/ascii/ to
check binaries, octals, etc…
• http://www.unix-manuals.com/refs/misc/ascii-
table.html
![Page 127: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/127.jpg)
World Wide Web (WWW)
• A way of presenting info on the Internet in the
form of hypertext documents.
• WWW ≠ Internet (why not?)
• When was WWW born?
• Was WWW designed by computer scientists?
• Was WWW designed in the U.S. (as the
Internet)?
![Page 128: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/128.jpg)
• How does WWW work?
• Client-server model
• URL (Uniform Resource Locator)
• http://www.nicholls.edu
• ftp://eclipse.nicholls.edu (what does the header “http” or
“ftp” mean?)
client server
request
answer
![Page 129: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/129.jpg)
• Specifically, • You instruct the client program (the browser, e.g.
IE or Firefox) on your local computer to get a Web document.
• The client locates the remote Web site.
• The client sends a request over the Internet to the server.
• The server on the Web sends a copy of the document you specified.
• The client program formats the document and displays it.
![Page 130: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/130.jpg)
File Compression and Archive
• Common file compressions
Compression Decompression Suffix exampe
compress uncompress .Z file.Z
gzip gunzip .gz file.gz
pkzip pkunzip .ZIP file.ZIP
tar (tape
archive)
tar .tar file.tar
![Page 131: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/131.jpg)
• $ gzip fn – compress file fn
• $ gunzip fn – uncompress file fn
• $ tar –cf fn.tar dir (or files)
• – create an archive file fn.tar from dir or (files)
• $ tar –tf fn.tar
• list contents of the archive
• $ tar –xf fn.tar
• restores the archived directory
![Page 132: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/132.jpg)
ZIP files w/ password protection
make sure zip is installed on your OS
![Page 133: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/133.jpg)
ZIP files w/ password protection
![Page 134: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/134.jpg)
on my Mac OS
![Page 135: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/135.jpg)
Computer Security
Cryptography
• Plaintext: original unencrypted text.
• Ciphertext: encrypted text.
• Algorithm: transform plaintext into ciphertext
(and vice versa). (need MATH here!)
• Key: info, such as a word, a phrase, required
to encrypt or decrypt a message.
![Page 136: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/136.jpg)
Encryption scenarios
• Secret-key encryption (aka: symmetrical
encryption):
use the same (shared secrete) key to encrypt and
decrypt a message
How to send the
secret key over
the Internet?
![Page 137: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/137.jpg)
Encryption scenarios
• Public-key encryption (aka: asymmetric
encryption):
• message is encrypted using public key (by the sender)
and decrypted using the private key (by the receiver).
• the public-key and private key are a matching pair
• public-key is used to encrypt messages.
• private-key is used to decrypt (public-key-encrypted)
messages.
• no other possibilities (this is the only way to work)
no need to send the
key over the Internet
![Page 138: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/138.jpg)
Encryption scenarios
• Public-key authentication (prove you are who you
claim you are): client sends request to server asking
for access, server encrypts a challenging message
using the public key and return it to the client. If the
client is able to understand the encrypted message,
then it proves that it holds the associated private key.
![Page 139: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/139.jpg)
plaintext ciphertext
ciphertext plaintext
A
A
alg
alg Internet
key
key
/R&
/R&
secret-key encryption
sender
receiver
![Page 140: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/140.jpg)
plaintext ciphertext
ciphertext plaintext
A
A
alg
alg Internet
public key
private key
/R&
/R&
sender
receiver
public-key encryption
![Page 141: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/141.jpg)
plaintext ciphertext
ciphertext plaintext
A
A
alg
alg Internet
private key
public key
/R&
/R&
public-key authentication
client
server
![Page 142: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/142.jpg)
RSA RSA RSA
RSA (the 3 MIT people) • The most well-known public-key encryption algorithm
• Based on the fact that there is no (currently) efficient way to factor a large number
• Industrial-strength de facto standard
• Built into web browsers (IE and others) and other software products
• RSA= Rivest, Shamir, and Adleman in 1977
• ACM Turing award winners!!!
• Restricted by US government for exporting to foreign countries (really?)
![Page 143: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/143.jpg)
ssh (secure shell) vs. telnet • both ssh and telnet are remote login utilities.
• telnet = plaintext (becoming/already obsolete)
• ssh = ciphertext, offers RSA public-key authentication. It also offers userid-password combination.
• to use ssh in Unix:
% ssh <hostname>
![Page 144: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/144.jpg)
public-key authentication w/ ssh
• conventional authentication : password
• secure authentication: public-key
• In Unix,
• generate a key pair: % ssh-keygen
and follow the instructions.
• copy the public key to the remote host, append it to
the file ~/.ssh/authorized_keys
![Page 145: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/145.jpg)
ssh-keygen screen shot
![Page 146: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/146.jpg)
• change file permission:
• % chmod u=rwx,go=rx ~/.ssh
• % chmod u=rw,go=r ~/.ssh/authorized_keys
• ready to go:
• % ssh user-name@host-name
• note: once public-key auth is set up, passwd auth will disappear (not needed)
• In PuTTY
• Refer to the handout (Putty manual) or
• http://the.earth.li/~sgtatham/putty/0.55/htmldoc/Chapter8.html
![Page 147: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/147.jpg)
Open putty-keygen, choose ssh2RSA
Generate the key-pair
save the private key to somewhere in your hard drive
Save the public key (may be optional)
![Page 148: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/148.jpg)
![Page 149: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/149.jpg)
![Page 150: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/150.jpg)
(or, newer)
![Page 151: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/151.jpg)
telnet to eclipse (the server), append the public-key to the file .ssh/authorized_keys in your home directory. (create such a file if you do not have one)
Make sure no one has right to write authorized_keys except you. (chmod go-w authorized_keys)
Logout eclipse (the server)
![Page 152: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/152.jpg)
![Page 153: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/153.jpg)
![Page 154: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/154.jpg)
Open putty, put eclipse.nicholls.edu in the host name field
Make sure ssh is selected
Click the Auth under Connection-SSH, click the browse button to open your private key file
Select “keyboard-interactive” (ssh2) for authentication methods
Click open button to start the login. (Note: eclipse will not ask you password for authentication, instead, a short message about public-key auth is displayed)
![Page 155: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/155.jpg)
Click
here
![Page 156: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/156.jpg)
Check
here
Click here
Click
here to
locate pk
![Page 157: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/157.jpg)
(or, newer)
![Page 158: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/158.jpg)
(or, newer)
![Page 159: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/159.jpg)
WULA!!! WULA!!!!
I can relax now.
![Page 160: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/160.jpg)
(or, newer)
WULA!!!!
Again!.
![Page 161: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/161.jpg)
WULA!!!!
the 3rd time!
![Page 162: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/162.jpg)
or, unfortunately,
![Page 163: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/163.jpg)
More about public-key authentication
and password (authentication)
The following is taken from
http://winscp.net/eng/docs/public_key
Public key authentication is an alternative
means of identifying yourself to a login
server, instead of typing a password. It is
more secure and more flexible, but more
difficult to set up.
![Page 164: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/164.jpg)
In conventional password authentication,
you prove you are who you claim to be by
proving that you know the correct password.
The only way to prove you know the
password is to tell the server what you think
the password is. This means that if the
server has been hacked, or spoofed, an
attacker can learn your password.
![Page 165: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/165.jpg)
Public key authentication solves this problem. You
generate a key pair, consisting of a public key
(which everybody is allowed to know) and a private
key (which you keep secret and do not give to
anybody). The private key is able to generate
signatures. A signature created using your private
key cannot be forged by anybody who does not
have that key; but anybody who has your public key
can verify that a particular signature is genuine.
![Page 166: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/166.jpg)
How does SSH work?
Symmetric keys are used by SSH in order to encrypt
the entire connection. Contrary to what some users
assume, public/private asymmetrical key pairs that
can be created are only used for authentication, not
the encrypting the connection. The symmetrical
encryption allows even password authentication to
be protected against snooping.
![Page 167: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/167.jpg)
How does SSH work?
After the symmetrical encryption is established to
secure communications between the server and
client, the client must authenticate to be allowed to
access the server. The server can use the public key
in the relevant file to encrypt a challenge message to
the client. If the client can prove that it was able to
decrypt this message, it has demonstrated that it
owns the associated private key. The server then
can set up the environment for the client.
![Page 168: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/168.jpg)
Now, relax and enjoy state-of-the-art
security, the Turing-award-winning RSA!
Wait a minute…
Quantum computing can break it!!!
what ???
![Page 169: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/169.jpg)
FYI: Why didn’t Bill Gates
receive Turing Award?
Which of the following brilliant ideas which have significant impacts on our life is originally from Microsoft (Bill Gates)?
• GUI for OS (windowing)
• Internet, TCP/IP
• Email, ftp
• WWW, http, html
• Scripting html document
• Web browser (graphical and non-graphical)
• Security, RSA
• Fundamental computer architecture
Answer : 0. Bill Gates is a (successful) businessman rather than a computer scientist
![Page 170: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/170.jpg)
• GUI for OS: Mac had GUI before Windows
• Internet, TCP/IP: back to 1960-70
• Email: Internet utility, ftp: Internet utility
• WWW, http, html: Tim Berners-Lee, CERN • http://www.cern.ch
• Scripting html document: JavaScript, Netscape
• Web browser (graphical and nongraphical): Netscape (Mosaic)
• Security, RSA: obvious
• Computer fundamental layout: John von Neumann • http://www-groups.dcs.st-
and.ac.uk/~history/Mathematicians/Von_Neumann.html
![Page 171: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/171.jpg)
Unix Startup Files
Startup Files allow users to customize working environment
Types of Startup Files • System-wide startup files
• Created by system administrator
• Contains commands to be used by your login shell
• Executed (if exist) first by your login shell.
• Login initialization files • created by users
• resides in your home directory
![Page 172: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/172.jpg)
• executed when users login
• Shell initialization files
• created by user
• resides in your home directory
• executed when a subshell starts up (whether it is a
login shell or not)
System-wide Startup Files
• Reside in /etc (typically)
![Page 173: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/173.jpg)
• File name depends on login shell
• sh, ksh, bash
• /etc/.profile
• csh, tcsh
• /etc/.login, /etc/.cshrc, /etc/csh.login, /etc/csh.cshrc
Login Initialization Files
• Depends on login shell
• sh, ksh, bash
• .profile
![Page 174: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/174.jpg)
• csh, tcsh • .login
Shell Initialization Files • Also called environment files
• Executed whenever a subshell is invoked
• Name depends on shell (name) • sh does not have a shell initialization file
• ksh : .kshrc
• csh: .cshrc
![Page 175: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/175.jpg)
• tcsh: .tcshrc; if .tcshrc not found, look for .cshrc
• bash: .bashrc
Order of Execution
• system-wide startup file
• shell initialization files
• login initialization files (order of last two may vary depending on systems)
![Page 176: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/176.jpg)
Variables
• Values of variables are setup in startup files to
customize the working environment
• Types of variables
• environment variables: predefined system shell
variables
• user-defined variables: personal variables created
by users
![Page 177: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/177.jpg)
Common Environment Variables
HOME Pathname of your home directory
PATH Directories where shell looks for commands
SHELL Pathname of your login shell
TERM Your terminal type
MAIL Pathname of system mail
USER Your user name
HOST The server’s name (or ip address)
![Page 178: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/178.jpg)
Setting Environment Variables (for the current
session)
• depends on shell
• sh, ksh, bash • ex: TERM=vt100
• csh, tcsh • ex: setenv TERM vt100
Listing Values of Environment Vars • sh, ksh, bash
• set
![Page 179: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/179.jpg)
• csh, tcsh
• setenv
Check the value of a specific Environment
Variable
• ex : echo $TERM
echo $SHELL
Special Variables of csh and tcsh
• csh and tcsh use the same environment variables as
the sh family. (e.g. HOME) (all capitals)
![Page 180: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/180.jpg)
• But csh and tcsh also have their own special
variables (e.g. home) (all lower-case)
pwd pathname of current working directory
history size of history list
home pathname of home directory
path dirs where shell looks for commands
term terminal type
shell pathname of shell
user your user name
prompt current prompt symbol
![Page 181: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/181.jpg)
• note: some variables have a uppercase counterpart as environment variable (e.g. home). For such variables, if their values are changed, their uppercase counterparts will be changed too (and vice versa, at least under tcsh. Note: commands for setting env vars and special vars are different )
• To list the values of all special variables (under csh/tcsh) • % set
• To set value of special variable (under csh/tcsh) • % set <var> = <value>
![Page 182: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/182.jpg)
User-defined Variables • To define your own variable, in .login (and .cshrc) add:
set <your-var> = <value>
ex: set web = /home/xing/public_html
(note the usage difference between set and setenv)
• To define your own variable, in .profile add:
<your-var>=<value>
ex: web=/home/xing/public_html
![Page 183: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/183.jpg)
• To use the newly defined variable
• % ls $web (note the $ )
• % cd $web (note the $)
Calendar Utility (questionable in Linux) • don’t confuse it w/ cal utility
• In .login (or .cshrc), add the line
calendar
• create a file named calendar in your home which contains a line involving today’s or tomorrow’s date.
• To run .login w/o logout, type
source .login
![Page 184: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/184.jpg)
History Utility
• % history
• gives some previously typed commands
• % !n
• to re-execute the command, where n is the number or the first
letter of the command you look for.
• % !!
• Execute the last command
• size is adjustable
• in .login and/or .chsrc add
set history = n (n is a number)
![Page 185: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/185.jpg)
Aliases
• used to shorten long command
• ex: in .login and/or .cshrc add
alias h “history”
• In .login and/or .cshrc add
alias rem “/bin/rm –i”
• rem will prompt you with yes/no, so it is a way to safely remove files.
Comments
• lines start with #
![Page 186: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/186.jpg)
Shell Scripting
What is a shell script? • A file that contains some shell commands and
is to be executed by the shell.
• Ex: # a simple script: shs
cal
date
w
How to execute shell scripts?
![Page 187: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/187.jpg)
• suppose shs is the name of above script
• submit shs as an argument for sh (or other
shells, csh, bash,…)
• % sh shs (or % csh shs)
• or
• % chmod u+x shs (mark shs executable)
• % shs (or ./shs)
Now you are scripting!!
![Page 188: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/188.jpg)
Subshells • when a script is executed, the login shell
actually calls another shell (a subshell) to process the script.
• Regardless of your login shell, you may use any shell to process your shell scripts.
• To specify which shell to use to process a script file, add the following line at the top of your script file. • #!/bin/<shell> <shell>=sh, csh, tcsh,…
![Page 189: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/189.jpg)
• ex:
#!/bin/sh
# a shell script
cal
date
w
• note
• #! is “one” character, cannot be separated
(#! is called “shebang” )
• blank space and new-line space matter here!
![Page 190: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/190.jpg)
Shell as a programming language
• Variables
• Input/output
• Arithmetic operations
• Conditional expressions
• Selection structures
• Loop structures
![Page 191: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/191.jpg)
Variables • Three kinds of variables can be used in shell
scripts.
• Environment variables: • e.g. HOME
• User-defined variables: • for users’ own needs
• Positional parameters: • store values from command-line arguments
![Page 192: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/192.jpg)
Positional parameters • indexed from 0 to 9: 0, 1, 2, …, 9
• $0 holds the filename of the script, $1 holds the first argument, S2 the second argument, $3 the third argument, … following the script file name
• ex:
#!/bin/sh
# a shell script, name: shs0
cal
date
w
echo $0 $1 $2 $3
![Page 193: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/193.jpg)
• run this script with (shs0 is the filename of the
script)
% shs0 i like it
$0 $1 $2 $3
arguments
![Page 194: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/194.jpg)
• Two special positional parameters
• $* -- lists all command-line arguments
• $# -- gives the number of arguments
• $0 is not considered an argument (here), but is the
file name (or command)
• ex:
echo “you typed” $# “arguments:” $*
![Page 195: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/195.jpg)
![Page 196: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/196.jpg)
• as a simple application, we can write a script that changes a file’s executable mode.
#!/bin/sh
# change a file’s executable mode
chmod u+x $1
echo $1 ‘can be executed now’
ls -l $1
Save it as “myscript”, it can make itself executable
% sh myscript myscript
![Page 197: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/197.jpg)
Set command and positional parameters • set can be used to assign values to positional parameters.
• the whole set of “original” arguments (if any) following the script name will be replaced by that produced by the set command
• ex:
set `date` # note the ` and ` pair, the command
# date will be executed
echo “Time:” $4 $5
echo “Day:” $1
echo “Date:” $3 $2 $6
![Page 198: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/198.jpg)
command date produces
Fri Aug 20 10:33:34 EST 2005
which is caught by set and consequently assigned
to
$1 $2 $3 $4 $5 $6
![Page 199: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/199.jpg)
![Page 200: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/200.jpg)
Labeling output from wc • $ wc <file>
gives the number of lines, number of words, and
number of characters in, and the name of <file>
• ex
$ wc lab1
5 17 84 lab1
• want to write a script “mywc”, s.t.
$ mywc lab1
![Page 201: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/201.jpg)
shows:
File: lab1
Lines: 5
Words: 17
Characters: 84
How can we do this?
![Page 202: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/202.jpg)
• #!/bin/sh
# label output from wc
set `wc $1` # execute wc $1 and put the result
# as the positional parameters
echo “File: $4”
echo “Lines: $1”
echo “Words: $2”
echo “Characters: $3”
![Page 203: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/203.jpg)
User-defined variables • combination of lower case letters, upper case letters,
underscore, and digits.
• first character cannot be digits
• ex: a, b1,c2, f_var
Assignment • <var>=<value> (no space in assignment)
• Ex: a=“this is a string”
b=$a
echo $b # prints “this is a string”
![Page 204: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/204.jpg)
Read statement • stores console input into variables (different from
positional arguments)
• ex:
#!/bin/sh
# read example
echo ‘what is your name?’
read name
echo ‘Well’, $name, “you typed “ $# “arguments”
echo “and they are:” $*
![Page 205: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/205.jpg)
![Page 206: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/206.jpg)
The expr Utility
• syntax : expr arg1 <op> arg2
<op> can be:
• +, -, \*, / (int division), % (int remainder)
• meaning: evaluates the expression
• ex: expr 3 + 4 7 (note space around +)
expr 3 / 4 0
expr 3 % 4 3
• Shell script can be written for simple arithmetic
operations.
![Page 207: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/207.jpg)
• #!/bin/sh
# add two numbers
sum=`expr $1 + $2`
echo “result is: “ $sum
$ add 3 4
result is: 7
$ add 4.9 4.3
----error (integer value expected)
![Page 208: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/208.jpg)
if-then statement • Syntax
if cond
then
commands
fi
ex:
• #!/bin/sh
set `date`
if test $1 = Fri
then
echo “Wula, weekend”
fi
test command compares values and checks
file types, and sets the (internal) exit status
depending on result
![Page 209: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/209.jpg)
Arguments of test
command
-d file file is a directory
-f file file is a file
-r file file is readable
-s file file size > 0
-x file file is executable
-w file file is writable
! -d file file is not a directory
! -f file file is not a file
! -r file file is not readable
! -s file file size not > 0
! -x file file is not executable
! -w file file is not writable
![Page 210: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/210.jpg)
n1 –eq n2 n1 = n2
n1 –ge n2 n1 >= n2
n1 –gt n2 n1 > n2
n1 –ne n2 n1 \= n2
n1 –lt n2 n1 < n2
n1 –le n2 n1 <= n2
n1, n2 are integers
s1 = s2 s1 equals s2
s1 != s2 s1 is not equal to s2
s1, s2 are strings
![Page 211: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/211.jpg)
If-then-else
• syntax
• if cond
then
commands
else
commands
fi
ex:
• #!/bin/sh
# if example
set `date`
if test $1 = Fri
then
echo “Wula, weekend”
else
echo “still have to work”
fi
![Page 212: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/212.jpg)
Remove files
#!/bin/sh
# file del
# delete files interactively
if test ! –f $1
then
echo “no such file” $1
else
echo “do you want to delete” $1 “(y/n)”
read choice
if test $choice = y
then
rm $1
echo $1 removed
else
echo $1 “not removed”
fi
fi
![Page 213: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/213.jpg)
Case statement • Syntax
case var in
p1) comd1; …; comdn ;;
p2) comd1;…; comdn;;
…..
pn) comd1;…; comdn ;;
*) comd1; …; comdn ;;
esac
ex: • #!/bin/sh
# case ex
• set `date`
• case $1 in
• Fri) echo "Friday";;
• Sat | Sun) echo "weekend too";
• echo "go fishing";;
• *) echo "not weekend";
• echo "need to work";;
• esac
![Page 214: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/214.jpg)
For-loops
• Syntax
for var in list
do
commands
done
Ex
• #!/bin/sh
for name in $*
do
finger $name
echo *********
done
![Page 215: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/215.jpg)
Ex:
#!/bin/sh
b="1 2 3 4 5 6 7 8 9 10"
for a in $b
do
echo "value is" $a
done
![Page 216: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/216.jpg)
Ex:
#!/bin/sh
# an improved spelling script
for word in `spell $1`
do
line=`grep -n $word $1`
echo " "
echo "misspelled word: $word"
echo "$line"
done
grep –n word file
find and print each
line in file that contains
word
![Page 217: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/217.jpg)
While-loops
• Syntax
while cond
do
commands
done
Ex:
• #!/bin/sh
c=10
while test $c –gt 0
do
echo value: $c
c=`expr $c – 1`
done
![Page 218: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/218.jpg)
shift command • shifts positional parameters ($1,$2,…) one
position to the right over the arguments
• $0 is not shifted
• ex: % mycomm 1 2 3 er ds
$0 $1 $2 $3 $4 $5
shift
% mycomm 1 2 3 er ds
$0 $1 $2 $3 $4
![Page 219: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/219.jpg)
part of a
shell script
![Page 220: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/220.jpg)
![Page 221: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/221.jpg)
C
![Page 222: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/222.jpg)
Overview
The simplest “hello, world” program
# include <stdio.h>
main()
{
printf("Hello, World\n");
}
![Page 223: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/223.jpg)
How to compile and execute C
programs? (gcc can be replaced by cc)
$ gcc test.c
$ a.out
Or $ gcc –o name test.c
$ name
![Page 224: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/224.jpg)
![Page 225: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/225.jpg)
Understanding the program
# include <stdio.h>
main()
{
printf("Hello World\n");
}
#-line: preprocessing directives.
Cause pre-processor to include the
header file stdio.h which contains info
about printf()
The function main()
where execution begins
Print the string “Hello Word”
on the screen (and advance to
the next line), by the function
printf()
![Page 226: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/226.jpg)
As a variation, what would be the
output?
# include <stdio.h>
main()
{
printf("Hello\nWorld”);
}
![Page 227: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/227.jpg)
![Page 228: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/228.jpg)
Basic Input and Output
Input:
• syntax:
• scanf(control string, other-args);
• ex:
• scanf("%d%d", &x, &y);
• semantics: read and convert two inputs from
the input stream into variables x and y in the
format specified in the control string
![Page 229: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/229.jpg)
scanf()
Format
(conversion
char)
To what?
c a character
d a decimal integer
f a floating point number (float)
lf a floating point number (double)
s a string
![Page 230: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/230.jpg)
Basic Input and Output
output:
• syntax: (formatted print)
• printf(control string, other-args);
• ex:
• printf("%3c%5c\n", ‘A’, ‘C’);
• semantics: print out characters A and C in the
format specified in the control string
• _ _ A _ _ _ _ C
![Page 231: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/231.jpg)
printf()
Format
(conversion
char)
how to print the arguments?
c as a character
d as a decimal integer
f as a floating point number
e as a floating point number in scientific notation
s as a string
for more info: search online C manual/tutorial
![Page 232: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/232.jpg)
![Page 233: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/233.jpg)
![Page 234: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/234.jpg)
![Page 235: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/235.jpg)
![Page 236: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/236.jpg)
width and
precision
positions taken by
precision is included in
width
![Page 237: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/237.jpg)
- will left-justify,
the default is
right-justify
![Page 238: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/238.jpg)
Fundamental Data Types
int
(long)
float
double
(long double)
char
(boolean? String?)
no boolean type
• 0 is “false”,
anything else is
“true”
no string type
• string is char array
• ex: char s[10];
![Page 239: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/239.jpg)
Identifiers
rule: {letter | _ }1{letter | _ |digit}0+
ex: a, _a, month_of_year
but not
not#me
101_n
-plus
![Page 240: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/240.jpg)
declaration of variables
syntax:
type var1, …, varn;
ex: int x, y;
double x1;
int x, y=3;
declaration and
initialization done in
“one step”
![Page 241: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/241.jpg)
Basic operations/operators
()
+ (unary) - (unary) ++ --
* / %
+ (binary) - (binary)
= += -= *= /=
(Q: should negative symbol and subtraction
symbol be distinguished in math?)
![Page 242: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/242.jpg)
Assignment statement
Java is the same as C
Syntax
• <var> = expression;
ex: a = 3;
x = x + 1;
etc…
![Page 243: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/243.jpg)
![Page 244: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/244.jpg)
![Page 245: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/245.jpg)
C is not “type safe”
compiler will not
complain, but you
will see a run-time
error.
![Page 246: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/246.jpg)
++ and --
increment / decrement operator
++a and a++ are different
ex:
![Page 247: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/247.jpg)
![Page 248: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/248.jpg)
When a++ or ++a are not alone, the
effect of the difference will be shown
• First all of, the expression a++ or ++a will be
evaluated (to yield a value)
• then, the yield value (i.e. evaluation result) will
be used in the surrounding context (since a++
or ++a are not “alone”)
![Page 249: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/249.jpg)
so, ++a causes a to be increased by 1
first, and the value of the expression ++a
is whatever stored in a.
a++, the value of the expression a++ is
the current value of a. Then a is
incremented by 1 after (the evaluation of
this expression)
use ++ or -- with caution (or, don’t use it)
![Page 250: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/250.jpg)
![Page 251: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/251.jpg)
Quick test using Java
interaction tab
the expression a++ is
being evaluated, and
the result is 1
the expression ++a is
being evaluated, and
the result is 2
![Page 252: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/252.jpg)
![Page 253: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/253.jpg)
A quick question: what is the
difference between a=1 and
a=1; in Java (and C)?
![Page 254: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/254.jpg)
sizeof () operator
gives the size (in byte) required in
memory for fundamental types
ex: (next slide)
![Page 255: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/255.jpg)
![Page 256: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/256.jpg)
![Page 257: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/257.jpg)
more about assignment
= is an operator in C, and has the
associated value
compare + (as in a + b) with
= (as in a = b)
a + b is an expression, so is a = b
a + b has a value, so does a = b
a + (b + c) makes sense,
![Page 258: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/258.jpg)
so does c = (a = b)
but , this style of programming, is not
suggested.
![Page 259: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/259.jpg)
ex:
![Page 260: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/260.jpg)
And, Java follows it
a=b is an expression (and thus will be
evaluated to a value)
a=b; is not an expression (and will not
be evaluated to a value)
![Page 261: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/261.jpg)
this example
should drive the
point to home
![Page 262: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/262.jpg)
char and int (C is not strongly
typed)
character can be considered as int
and vice versa (see next slide)
note: not saying int is the same type as
char (4 bytes vs 1 byte). We cannot
declare a variable as type int and char at
the same time
again, this style of programming is not
suggested (it is allowed of course)
![Page 263: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/263.jpg)
![Page 264: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/264.jpg)
Relational , equality, and logical
operators
<
>
<=
>=
==
!=
!
&&
||
same meaning as in Java
false = any zero-value
(0, 0.0, or NULL, …)
true = any non-zero value
![Page 265: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/265.jpg)
ex:
![Page 266: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/266.jpg)
![Page 267: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/267.jpg)
Consider this….
There is no logical type (boolean type) in
C
But, there are logical operators in C (!,
&&, ||)
So, what is the response to the following
expression in C (and Java)?
3 < j < 5 when j =7
![Page 268: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/268.jpg)
![Page 269: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/269.jpg)
3 < j < 5 is the same as (3 < j) < 5
3 < j yields 1 (true), when j=7. so
(3 < j) < 5 is the same as
1 < 5,
which yields 1 (true)
lesson learned: typing is important (so
boolean type is needed)
![Page 270: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/270.jpg)
true in C
false in C
![Page 271: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/271.jpg)
“strange” things ...
![Page 272: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/272.jpg)
In Java, it’s a different story…,
due to STRONG typing in Java
![Page 273: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/273.jpg)
More about what typing can
cause ...
while/if (a = 1)
………… /* do sth */
while/if (a == 1)
….. /* do sth */
![Page 274: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/274.jpg)
both are syntactically correct in C
the first one will run forever, and thus
cause a perplex...
the second one is what we want..
![Page 275: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/275.jpg)
![Page 276: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/276.jpg)
![Page 277: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/277.jpg)
Java won’t compile something
like this
this shows typing is
important !!!
![Page 278: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/278.jpg)
Selections
if-statement
syntax
• if (expression)
statements
ex:
if ( a == 1)
x = y;
![Page 279: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/279.jpg)
if-else statement
syntax
• if (expression)
statements
else
statements
![Page 280: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/280.jpg)
ex:
• if ( x == y)
{
i =1; j =2;
}
else
{ i = j;
}
![Page 281: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/281.jpg)
ex: is the following code syntactically
correct? if not, what is wrong?
if (i == j)
{ i = i+1;
j = j+2;
};
else
i = j-1;
![Page 282: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/282.jpg)
which “if” does the “else” go w/?
ex: is the following code
semantically clear?
if (i == j)
if (a == 2)
i = i+1;
else
j = j-1;
if (i == j)
if (a == 2)
i = i+1;
else
j = j-1;
![Page 283: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/283.jpg)
rule : the else matches with nearest if.
So the left one is will be “chosen”.
but, what if we intend to do the other
one?
![Page 284: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/284.jpg)
what if we want to do the “right”
one
ex: is the following code
semantically clear?
if (i == j)
if (a == 2)
i = i+1;
else
j = j-1;
if (i == j)
{ if (a == 2)
i = i+1;
}
else
{ j = j-1;
}
![Page 285: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/285.jpg)
Is this else-if statement?
if (….)
printf(…);
else if (…)
printf(….);
![Page 286: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/286.jpg)
while-loop
syntax:
• while (expression)
statements
usage:
the same as Java (Java follows C)
![Page 287: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/287.jpg)
![Page 288: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/288.jpg)
![Page 289: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/289.jpg)
for-loop
same as Java
syntax:
• for (expr1; expr2; expr3)
statements
next statement
meaning interpreted in terms of while-
loop
![Page 290: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/290.jpg)
expr1;
while (expr2)
{
statements;
expr3;
}
next statement
![Page 291: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/291.jpg)
ex:
![Page 292: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/292.jpg)
the conditional operator ?:
?: is ternary
syntax:
expr1 ? expr2 : expr3
if expr1 is true, then expr2 will be the result
of the entire expression, otherwise expr3
will be the result of the expression.
![Page 293: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/293.jpg)
ex:
![Page 294: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/294.jpg)
![Page 295: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/295.jpg)
what is going on in Java?
![Page 296: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/296.jpg)
![Page 297: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/297.jpg)
It will be evaluated … But, what
would be the type of evaluation
result?
what would be the type
of the expression????
![Page 298: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/298.jpg)
functions (modular
programming)
#include <….>
function prototypes (optional )
function defs
main ()
{…..}
![Page 299: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/299.jpg)
ex:
![Page 300: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/300.jpg)
functions
![Page 301: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/301.jpg)
recursive functions
![Page 302: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/302.jpg)
Pointers, 1-d Arrays, Strings
Pointers
• variables holding memory addresses
1-d arrays
• vectors (same as Java)
• index starts from 0 (not 1)
Strings
• 1-d array of characters
• last value of a string is ‘\0’
![Page 303: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/303.jpg)
example of strings
• “abcde” is stored as
‘a’ ‘b’ ‘c’ ‘d’ ‘e’ ‘\0’
![Page 304: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/304.jpg)
![Page 305: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/305.jpg)
![Page 306: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/306.jpg)
pointer declaration:
• ex: int *p;
• meaning: p is a pointer to type int; or p is a
variable of type int *; or p refers to some
memory location which holds an int value; or
*p is of type int.
p ?
(NULL)
![Page 307: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/307.jpg)
if p is a pointer, then *p (called pointer
dereferencing) means the memory
location (cell) which is pointed by p.
ex:
int q=1, *p;
p = &q;
p
*p
q 1
![Page 308: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/308.jpg)
so,
int *p;
can be understood in both ways:
• as (int *) p; i.e., p is variable of type int *.
or
• as int (*p); i.e., *p is a variable of type int.
![Page 309: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/309.jpg)
Example
next slide, study it carefully, as it
involves some fundamental facts about
pointers.
![Page 310: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/310.jpg)
![Page 311: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/311.jpg)
Now, why doesn't it work?
![Page 312: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/312.jpg)
same thing as before …
![Page 313: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/313.jpg)
this
(changing
p to &p) is
not the
problem.
It is
supposed
to be p (a
pointer).
![Page 314: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/314.jpg)
to fix it:
![Page 315: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/315.jpg)
type synonym : typedef
give a new name for existing types:
ex:
• typedef char * string;
• typedef int number;
• string s1;
• number n;
![Page 316: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/316.jpg)
![Page 317: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/317.jpg)
structure (or record)
syntax
• struct name
{
type field;
…..
}
name is optional
![Page 318: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/318.jpg)
ex:
after this, struct complex (together) is
used as a type
![Page 319: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/319.jpg)
accessing members of a structure
• use the “.” operator
structure_var . member
or use the “->” operator
ptr_to_structure -> member
![Page 320: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/320.jpg)
![Page 321: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/321.jpg)
or, equivalently
![Page 322: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/322.jpg)
or, (maybe better)
![Page 323: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/323.jpg)
or, w/ pointers
![Page 324: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/324.jpg)
or, w/ header file
Put definition (and other things) of type
complex is in a header file, say,
complex.h.
![Page 325: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/325.jpg)
then, to have better moularity
![Page 326: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/326.jpg)
Use structure w/ functions
![Page 327: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/327.jpg)
HTML
![Page 328: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/328.jpg)
HTML Basics
HTML – Hypertext Markup Language
Background
• Who: Tim Berners-Lee
• Where: CERN, Swiss
• When: 1989
• http://public.web.cern.ch/Public/Welcome.html
Used to write WWW (web) pages
![Page 329: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/329.jpg)
Structure of a HTML document • <html>
<head><title> …..</title></head>
<body>
…………….
…………..
</body>
</html>
![Page 330: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/330.jpg)
• Note:
• A html file is a plain text file
• <..> -- opening tag
• </..> -- closing tag
• Opening tags are paired with corresponding
closing tags (not so strict)
• Place the html file in the public_html directory on
eclipse
• an example (next page)
![Page 331: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/331.jpg)
![Page 332: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/332.jpg)
![Page 333: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/333.jpg)
Type styles • Tags to typeset documents
• Heading style • <H1> largest and boldest
• <H2>
• …
• <H6>
• <cite> -- citation
• <em> -- emphasis
Down in size
![Page 334: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/334.jpg)
• <strong> -- bold
• <code>, <kbd> -- monospaced font
• <address> -- italic, email, phone #, address
• <big> -- big font
• <small> -- small font
• <sup> -- superscript
• <sub> -- subscript
![Page 335: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/335.jpg)
Ex: <H1> Look Here </H1>
Look Here
B<sup>2</sup>
B2
![Page 336: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/336.jpg)
Horizontal alignment of text
• Syntax:
• <p> makes a paragraph
• <p align = x > …..</p>
x = left, right, center
• <center> ……….</center> (will center and make
a paragraph)
• Ex: <p align=right> this line </p>
![Page 337: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/337.jpg)
Comments (which one, confusing) • <!-- ……… -->
• <! …… >
• Def: • Comment declaration: <! … >
• Comment contents: start with -- end with -- contain no occurrence of –
• A comment is: comment declaration which contains zero or more comment contents
• So <!>, <!----> are all legal comments
• But <!-----> is not
• Unfortunately, not many browsers coded to recognize it.
![Page 338: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/338.jpg)
Font sizes
• Syntax: <font size=x> … </font>
• x can be 1,2,…, 7
• From small to large
• Default size = 3
• Ex: <font size=5> large font </font>
![Page 339: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/339.jpg)
Fixed type styles • Unlike relative style tags (e.g. <h1>), fixed type styles do
not vary from one browser to another.
• style tag
bold <b> </b>
italic <i> </i>
underscore <u> </u>
typewriter <tt> </tt>
strikeout <s> </s>
![Page 340: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/340.jpg)
Line and paragraph breaks
• <br> ends a line w/o adding any space
• <p> ends a line and adds a line space
• <nobr> </nobr>
prevents texts and graphics from
breaking and reflowing
![Page 341: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/341.jpg)
Text links
• <a href=“…...... “> …….…</a>
anchor
Hypertext ref name of link
text to click
![Page 342: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/342.jpg)
ex:
• <a href=“art.html”>click here</a>
• <a href=“lab1.txt”>click here</a>
• <a href=“http://www.nicholls.edu”>click here</a>
• <a href=“mailto:[email protected]"”>click here to mail
me</a>
![Page 343: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/343.jpg)
Graphics
• <img align=x src=“….” width=“..” height=“…”>
• ex: <img src=“clips.gif”>
optional name of pic
x= top, bottom, middle
![Page 344: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/344.jpg)
• Border on graphics
• <img src=“……” border=“…”>
• Graphic links
• <a href=“…..”> <img src=“…..”> </a>
pixels
Name of
resource picture
![Page 345: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/345.jpg)
Background color, text color, and link color • <body bgcolor=“#302030” text=“#246050”
link=“#505050”>
• https://html-color.codes/
• color name(“red”), hex-code (“#ffffff”), rgb-code(“(0,34,0)”)
• List • unordered list
• <ul type=x> x = circle or square w/wo “”
<li> …
<li> ….
</ul>
optional
![Page 346: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/346.jpg)
![Page 347: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/347.jpg)
![Page 348: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/348.jpg)
• Ordered list • <ol type=x> x=1,A,a,i
<li> ….
<li> …..
</ol>
Dividing rules • <hr>
• <hr size=“…” width=“…” align=x>
x= left, right, center
height length
![Page 349: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/349.jpg)
![Page 350: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/350.jpg)
![Page 351: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/351.jpg)
Links within documents
• <a href=“#....”> …. </a>
• <a name=“…”>….</a>
• Ex: <a href=“#comp”>computer</a>
<a name=“comp”> computer def </a>
text
text same
![Page 352: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/352.jpg)
![Page 353: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/353.jpg)
![Page 354: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/354.jpg)
![Page 355: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/355.jpg)
![Page 356: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/356.jpg)
Block quote • <blockquote>
….
</blockquote>
Background (design) • <body background=“…..”>
Preformatted text • <pre>
………….
</pre>
indented
Graphics file
Exact appearance
![Page 357: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/357.jpg)
Example
• Using what we have covered so far, we can
compose the following webpage. (next slide)
![Page 358: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/358.jpg)
![Page 359: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/359.jpg)
![Page 360: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/360.jpg)
Table • <table border>
<caption align= … > ……</caption>
<tr>
<th> … </th> <th> … </th>
</tr>
<tr>
<td>….</td> <td>….</td>
</tr>
</ table>
Top or bottom caption
row Heading cell
Table data
Optional (show or not show border)
![Page 361: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/361.jpg)
Borders, spacing, padding
• <table
border=10
cellspacing=6
cellpadding=10>
Width of frame
Space between 2 cells
Space between text in a cell
and cell gridline
![Page 362: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/362.jpg)
Alignment
• Put align=x (x=left, center, right) in
<th>, <td>, or <tr>
• Ex: <tr align=center>….. </tr>
whole row is centered
<td align=left>…..</td>
only this cell is aligned to left
![Page 363: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/363.jpg)
Width control
• <table width=400>
specifies the width of the table
• <th width=50>
specifies the width of the cell
![Page 364: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/364.jpg)
Spanning rows and/or columns
• <th rowspan=2> …..</th>
• <th colspan=2> …..</th>
• <td rowspan=2> …..</td>
• <td colspan=2> …..</td>
![Page 365: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/365.jpg)
![Page 366: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/366.jpg)
![Page 367: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/367.jpg)
![Page 368: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/368.jpg)
![Page 369: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/369.jpg)
![Page 370: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/370.jpg)
![Page 371: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/371.jpg)
![Page 372: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/372.jpg)
![Page 373: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/373.jpg)
Forms
The <form> element • <form action=“…” method=“…”>
put form elements here
</form>
Input texts into forms • Using the <input> element: Generate various
ways for users to enter info into forms • <input …..some attributes…… >
• Common attributes: type, name, value
![Page 374: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/374.jpg)
• Using the <textarea> element: allows a
paragraph of texts to be entered
• <textarea …some attributes….. >
some default text
</textarea>
![Page 375: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/375.jpg)
![Page 376: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/376.jpg)
![Page 377: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/377.jpg)
Input selections
• Checkbox
• <input type=“checkbox” name=…. value=...>
• Radio button
• <input type=“radio” name=… value=...>
• Drop-down list
• <select name=…size=…>
<option value=…> ….</option>
• </select>
# of lines visible
![Page 378: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/378.jpg)
![Page 379: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/379.jpg)
![Page 380: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/380.jpg)
![Page 381: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/381.jpg)
![Page 382: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/382.jpg)
![Page 383: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/383.jpg)
Submitting and clearing forms
• <input type=“submit”>
• <input type=“reset”>
Generate a submit button and a reset button
respectively
![Page 384: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/384.jpg)
![Page 385: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/385.jpg)
![Page 386: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/386.jpg)
Form Processing -- CGI
CGI programs– Common Gateway Interface
programs. They are used to process forms
CGI programs can be written in any language
supported by the Web server, e.g., C, C++,
Java, Perl.
CGI programs are installed on server and
specified by the action attribute of the form tag.
![Page 387: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/387.jpg)
Ex:
• <FORM METHOD="POST"
ACTION="http://web.mit.edu/bin/cgiecho/wwwdev
/cgiemail/questions3.txt">
• <FORM METHOD=“get" ACTION=“./cgi-bin/test.pl”>
• “get” appends data from form to the end of URL in the
resulting window; “post” does not do so and merely
send form data to the Web server to be processed.
![Page 388: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/388.jpg)
MIT cgiemail program
Free CGI program for Unix
Easy to use
http://web.mit.edu/wwwdev/cgiemail/
It collects data from a form and sends
them to a specified email address in a
specified format
![Page 389: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/389.jpg)
Steps to make cgiemail work on
our Unix
Go to cgiemail website, download binaries cgiecho and cgiemail to your cgi-bin directory, say, /home/xing/public_html/cgi-bin.
Rename them as cgiecho.cgi and cgiemail.cgi
Change file mode of these two files (chmod 755 ….)
Create an email template (an ASCII file) which specifies the format of the email which will be sent to you (or someone else) by the web server.
Here is an example of the email template
![Page 390: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/390.jpg)
From: [email]
Subject: questions three
What is your name? [yourname]
What is your quest? [quest]
What is your favourite colour? [colour]
This allows the form data to be sent to cmps-
[email protected] w/ sender being identified as [email]
![Page 391: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/391.jpg)
Put this file (say file name is quest3.txt) into your public_html directory,e.g., /home/xing/public_html
Test this file with your browser to make sure it is readable.
Create a html form in your public_html directory,say, /home/xing/public_html
An example of the html file is as follows: note that the values of the name attributes MUST be the same as that in the email template
![Page 392: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/392.jpg)
<html>
<head><title> form test</title></head>
<body>
<FORM METHOD="get"
ACTION="http://eclipse.nicholls.edu/~xing/cgi-bin/cgiecho.cgi/~xing/quest3.txt">
Your e-mail address: <INPUT NAME="email"><p>
Your name: <INPUT NAME="yourname"><p>
Your quest: <INPUT NAME="quest"><p>
Your favourite colour: <INPUT NAME="colour"><p>
<INPUT TYPE="submit" value="click to see response">
</FORM>
</body>
</html>
![Page 393: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/393.jpg)
Set the value of action of the form tag to be:
ACTION=http://eclipse.nicholls.edu/~xing/cgi-bin/cgiecho.cgi/~xing/quest3.txt to echo the form data (no email will be sent) or
ACTION=http://eclipse.nicholls.edu/~xing/cgi-bin/cgiemail.cgi/~xing/quest3.txt to send form data as an email
Save the file in your public_html directory, say, /home/xing/public_html/myform.html
Open myform.html using your favorite browser
![Page 394: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/394.jpg)
The email template
![Page 395: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/395.jpg)
The html form file
![Page 396: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/396.jpg)
Executing the html form file
Click it
![Page 397: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/397.jpg)
Response from clicking the
button
![Page 398: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/398.jpg)
What is in my mail box
![Page 399: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/399.jpg)
XHTML
![Page 400: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/400.jpg)
Overview
SGML
HTML
XML
XHTML
![Page 401: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/401.jpg)
SGML • Standard Generalized Markup Language
• Widely used for large-scale documentation project (IRS, DoD, Health care…)
• 1986
HTML • Hyper Text Markup Language
• First language for WWW
• Early 1990
![Page 402: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/402.jpg)
• Limitations (for example)
• Loose syntax, (“” or no “”, close tag or not?,
lowercase or capital?...)
• web browser forgiving, but not new wireless
devices (cell phone, PDA, car navigator…)
• Can’t be extended
XML • Extensible Markup Language
• 1998, by W3C (WorldWideWeb Consortium)
• Motivated by the limitations of HTML
![Page 403: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/403.jpg)
XHTML
• Combination of XML and HTML
• 2000, XHTML 1.0
![Page 404: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/404.jpg)
Converting HTML to XHTML
All mark elements must be lowercase • Ex: HTML: <TITLE> … </TITLE>
XHTML: <title> … </title>
Every open tag must correspond to a close tag • Ex: HTML: <ol>
<li> item1
<li> item2
</ol>
XHTML: <ol>
<li> item1 </li>
<li> item2 </li>
</ol>
![Page 405: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/405.jpg)
Empty-element syntax • Ex: HTML: <BR>
XHML: <br />
Every attribute must have a value. The value needs to be surrounded by single or double quote marks • Ex: HTML: <input type=button checked>
XHTML: <input type=“button” checked=“checked” />
![Page 406: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/406.jpg)
Proper nesting of elements is required • Ex: HTML: <p><em>…</p></em>
XHTML: <p><em> … </em></p>
All XHTML documents must contain DOCTYPE declaration and may, optionally, contain an XML declaration • <?xml version="1.0" encoding="UTF-8"?>
• <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
• "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![Page 407: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/407.jpg)
The root element <html> must contain
an XHTML namespace
• <html xmlns="http://www.w3.org/1999/xhtml">
![Page 408: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/408.jpg)
Three types of DTD (Document
Type Definition)
Transitional
Frameset
Strict
Replace any by another in DOCTYPE
declaration
![Page 409: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/409.jpg)
example
![Page 410: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/410.jpg)
![Page 411: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/411.jpg)
Validation of XHTML documents
Go to http://validator.w3.org
Submit your document
Example: submitting the previous
sample xhtml document
![Page 412: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/412.jpg)
![Page 413: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/413.jpg)
![Page 414: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/414.jpg)
![Page 415: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/415.jpg)
Introduction to
JavaScript
![Page 416: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/416.jpg)
Background
In early 1990, “www” so “hot” that everyone was talking about “.com”
In 1995, Netscape (Brendan Eich) decided to script the HTML, the scripting language was called LiveScript
Netscape and Sun worked together to implement the scripting language into Netscape Navigator 2.0. The name changed from LiveScript to JavaScript (for marketing purpose)
Microsoft followed this idea, released Jscript the next year
![Page 417: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/417.jpg)
JavaScript vs. Java
JavaScript ≠ Java
JavaScript : loosely typed
Java: strongly typed.
JavaScript: tied w/ web programming
Java: general purpose
![Page 418: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/418.jpg)
Basic Structure
…..<head> ……
<script type="text/javascript" >
js code here
</script>
…………..
</head>
<body>
…………
<script type="text/javascript" >
js code here
</script>
………..
</body>
The <script>…</script>
can be inserted at
different places
![Page 419: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/419.jpg)
or
…..<head> ……
<script type="text/javascript" src=…a-js-file…>
js code
</script>
…………..
</head>
<body>
…………
<script type="text/javascript“ src=…a-js-file…. >
js code
</script>
………..
</body>
![Page 420: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/420.jpg)
JS Syntax and Semantics
Similar to that of Java (skip)
Ex:
• for (i=0; i<10; i++)… for-loop
• while (i < 10)… while-loop
• var a; variable declaration
• a =1; assignment statement
• if (a <=b)… branching
![Page 421: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/421.jpg)
example: loop
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> js test </title>
<script type="text/javascript" >
var i;
for (i=1;i<=10;i++)
document.write("do it"+i+"time <br />");
document.write("<h1> stop the loop! </h1>");
</script>
</head>
<body>
<p>
<a href="http://validator.w3.org/check?uri=referer">
<img
src="valid-xhtml10.gif"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</p>
</body>
</html>
![Page 422: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/422.jpg)
![Page 423: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/423.jpg)
Or, put the js into another file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> js test </title>
<script type="text/javascript" src=“./jsfiles/x.js”>
</script>
</head>
<body>
<p>
<a href="http://validator.w3.org/check?uri=referer">
<img
src="valid-xhtml10.gif"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</p>
</body>
</html>
path of the file x.js
![Page 424: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/424.jpg)
example: loop
// the x.js file
var i;
for (i=1;i<=10;i++)
document.write("do it"+i+"time <br />");
document.write("<h1> stop the loop! </h1>");
![Page 425: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/425.jpg)
It will do the same thing
![Page 426: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/426.jpg)
example: branching
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> js test </title>
<script type="text/javascript" >
var answer = window.prompt("who are you? Type your name here", "???");
if (answer == "John")
window.alert("Hello, John");
else
window.alert("fatal error! memeory dump! Shut down the system!");
</script>
</head>
<body>
<p>
<a href="http://validator.w3.org/check?uri=referer">
<img
src="valid-xhtml10.gif"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</p>
</body>
</html>
![Page 427: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/427.jpg)
example: branching
![Page 428: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/428.jpg)
example: function (rewriting of
previous example)
<head>
<title> js test </title>
<script type="text/javascript" >
function doIt(x)
{
if (x == "John")
window.alert("Hello, John");
else
window.alert("fatal error! memeory dump! Shut down the system!");
}
</script>
</head>
<body>
<script text="text/javascript">
var answer = window.prompt("who are you? Type your name here", "???");
doIt(answer);
</script>
<!– the logo here -->
</body>
</html>
![Page 429: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/429.jpg)
Note:
Browsers load (x)html codes, from top to
bottom, into memory
Common practice: put functions inside
<head></head> element so that the
browser “knows” the functions before
they are invoked.
![Page 430: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/430.jpg)
Check Boxes
Purpose: make multiple (one or more)
choices
How to make checkboxes?
How to check which boxes are checked?
Ex: (2 approaches, both fine)
![Page 431: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/431.jpg)
<script type="text/javascript" >
function showIt(f)
{
f.result.value=""; // reset the result value
if (f.food0.checked)
{ f.result.value="steak"; }
if (f.food1.checked)
{ f.result.value=f.result.value+",seafood"; }
if (f.food2.checked)
{ f.result.value=f.result.value+",vege"; }
}
</script>
![Page 432: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/432.jpg)
<form name="myform">
Select the ones you like: (all that apply) <br />
<input type="checkbox" name="food0" /> steak <br />
<input type="checkbox" name="food1" /> seafood <br />
<input type="checkbox" name="food2" /> vege <br />
<input type="button" value="click to see your choice(s)" onclick="showIt(document.myform);" /> <br />
<input type="text" name="result" value="" />
</form>
![Page 433: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/433.jpg)
<script type="text/javascript" >
function showIt(f)
{
f.result.value=""; // reset the result value
if (f.food[0].checked)
{ f.result.value="steak"; }
if (f.food[1].checked)
{ f.result.value=f.result.value+",seafood"; }
if (f.food[2].checked)
{ f.result.value=f.result.value+",vege"; }
}
</script>
![Page 434: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/434.jpg)
<form name="myform">
Select the ones you like: (all that apply) <br />
<input type="checkbox" name="food" /> steak <br />
<input type="checkbox" name="food" /> seafood <br />
<input type="checkbox" name="food" /> vege <br />
<input type="button" value="click to see your choice(s)" onclick="showIt(document.myform);" /> <br />
<input type="text" name="result" value="" />
</form>
![Page 435: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/435.jpg)
![Page 436: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/436.jpg)
Radio Buttons
Purpose: you can only choose ONE
choice, not allowed to choose more than
one.
How to create radio buttons?
How to check which button is selected?
Ex: make a choice and show what
choice is made.
![Page 437: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/437.jpg)
<script type="text/javascript" >
function showIt(f)
{
if (f.food[0].checked)
{ f.result.value="steak"; }
else
{
if (f.food[1].checked)
{ f.result.value="seafood"; }
else
{if (f.food[2].checked)
{ f.result.value="vege"; }
else
{f.result.value="nothing is chosen";}
}
}
}
![Page 438: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/438.jpg)
<form name="myform">
Make your choice: <br />
<input type="radio" name="food" /> steak <br />
<input type="radio" name="food" /> seafood <br />
<input type="radio" name="food" /> vege <br />
<input type="button" value="click to see your choice" onclick="showIt(document.myform);" /> <br />
<input type="text" name="result" value="" />
</form>
![Page 439: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/439.jpg)
![Page 440: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/440.jpg)
a better treatment might be the following:
function showIt(f)
{
var i;
for (i =0; i<3; i++)
{
if (f.food[i].checked)
{ f.result.value=f.food[i].value;
break;
}
}
}
![Page 441: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/441.jpg)
Or the following:
function showIt(f)
{
alert("# of elements="+f.elements.length);
var i;
for (i =0; i<3; i++)
{
if (f.elements[i].checked)
{ f.result.value=f.elements[i].value;
break;
}
}
}
![Page 442: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/442.jpg)
<form name="myform">
Make your choice: <br />
<input type="radio" name="food" value="steak" /> steak <br />
<input type="radio" name="food" value="seafood" /> seafood <br />
<input type="radio" name="food" value="vege" /> vege <br />
<input type="button" value="click to see your choice" onclick="showIt(document.myform);" /> <br />
<input type="text" name="result" value="" />
</form>
<!-- Note each <input> element has a value now. -->
![Page 443: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/443.jpg)
You will see the same result
![Page 444: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/444.jpg)
![Page 445: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/445.jpg)
![Page 446: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/446.jpg)
![Page 447: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/447.jpg)
onmouseout
![Page 448: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/448.jpg)
onmouseover
![Page 449: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/449.jpg)
Swap to “3l” image every 3 seconds
![Page 450: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/450.jpg)
Swaps to “logo” image every 3 seconds
![Page 451: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/451.jpg)
Lab25 (last one)
Find two of your favorite pictures and
swap them every 2 second.
Print the screen shots and XHTML code
![Page 452: Unix, C Programming, and (X)HTML · 2019. 10. 24. · Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) X Window System](https://reader036.vdocuments.net/reader036/viewer/2022071109/5fe487ef2808684f67104ac3/html5/thumbnails/452.jpg)
Problems w/ eclipse?