Script started on Mon Nov 17 17:29:01 2025 macbook:logs> echo attendance code 462 attendance code 462 macbook:logs> cd ../programs/unix_ch13 macbook:unix_ch13> cat talk.c // Linux for Programmers and Users, Glass/Ables, page 503 #include #include #include #include #include #define READ 0 /* The index of the read end of the pipe */ #define WRITE 1 /* The index of the write end of the pipe */ char* phrase = "Stuff this in your pipe and smoke it"; int main() { int fd [2], bytesRead; char message [100]; /* Parent process' message buffer */ pipe (fd); /*Create an unnamed pipe */ if (fork () == 0) /* Child, writer */ { close(fd[READ]); /* Close unused end */ write (fd[WRITE],phrase, strlen (phrase) + 1); /* include NULL*/ close (fd[WRITE]); /* Close used end */ } else /* Parent, reader*/ { close (fd[WRITE]); /* Close unused end */ bytesRead = read (fd[READ], message, 100); printf ("Read %d bytes: %s\n", bytesRead, message); /* Send */ close (fd[READ]); /* Close used end */ } return 0; } macbook:unix_ch13> gcc talk.c -o talk macbook:unix_ch13> ./talk Read 37 bytes: Stuff this in your pipe and smoke it macbook:unix_ch13> cd ../unix_ch5 macbook:unix_ch5> vi testfor.sh macbook:unix_ch5> cp testfor.sh testfor2.sh macbook:unix_ch5> vi testfor2.sh macbook:unix_ch5> ls -l testf* -rwxr-xr-x 1 mweeks staff 61 Sep 12 15:21 testfor.sh -rwxr-xr-x 1 mweeks staff 89 Nov 17 18:03 testfor2.sh macbook:unix_ch5> ./testfor2.sh param: red param: green param: blue param: yellow param: orange macbook:unix_ch5> cat testfor2.sh params="red green blue yellow orange" for value in $params do echo param: $value done macbook:unix_ch5> cat testif.sh echo "enter a word: " read v1 if [ -e $v1 ] then echo "A file by that name exists." else echo "No file by that name exists." fi macbook:unix_ch5> ./testif.sh enter a word: testfor2.sh A file by that name exists. macbook:unix_ch5> ./testif.sh enter a word: testforty2.sh No file by that name exists. macbook:unix_ch5> cat test_file_exists.sh if [ -e "$1" ]; then echo "The file exists." fi% macbook:unix_ch5> macbook:unix_ch5> ./test_file_exists.sh testfor2.sh The file exists. macbook:unix_ch5> ./test_file_exists.sh testforty2.sh macbook:unix_ch5> grep until * testuntil.sh:until [ $x -gt 3 ] macbook:unix_ch5> cat testuntil.sh x=1 until [ $x -gt 3 ] do echo x = $x x=`expr $x + 1` done macbook:unix_ch5> ./testuntil.sh x = 1 x = 2 x = 3 macbook:unix_ch5> cd ../unix_ch12 macbook:unix_ch12> gcc reverse.c clang: error: no such file or directory: 'reverse.c' clang: error: no input files macbook:unix_ch12> ls rev* reverse_unix_ch12.c reverse_unix_original.c macbook:unix_ch12> gcc reverse_unix_ch12.c macbook:unix_ch12> ./a.out reverse ("cat") = tac reverse ("noon") = noon macbook:unix_ch12> cd make_project macbook:make_project> ls *h db.h parts.h supps.h macbook:make_project> cat db.h #include #include "parts.h" #include "supps.h" macbook:make_project> cat parts. cat: parts.: No such file or directory macbook:make_project> cat parts.h #include #include #define N 10 int a[N]; void array_set(int, int); int array_length(); void array_init(int *); macbook:make_project> cat supps.h #include #include #define N 10 bool is_prime(int); macbook:make_project> cat supps.c /********************************************************* * From C PROGRAMMING: A MODERN APPROACH, by K. N. King * * Copyright (c) 1996 W. W. Norton & Company, Inc. * * All rights reserved. * * This program may be freely distributed for class use, * * provided that this copyright notice is retained. * *********************************************************/ /* prime.c (Chapter 9, page 162) */ /* Tests whether a number is prime */ // altered a bit to use as an example for "make" #include "supps.h" bool is_prime(int n) { int divisor; if (n <= 1) return false; for (divisor = 2; divisor * divisor <= n; divisor++) if (n % divisor == 0) return false; return true; } macbook:make_project> cat parts.c #include "parts.h" void array_init(int *p) { int i; for (i=0; i= 0) && (index < N)) a[index] = value; } macbook:make_project> cat db.c #include "db.h" int main() { int i; printf("The array has %d values\n", array_length()); array_init(a); i = array_length() - 2; array_set(i, 5); if (is_prime(a[i])) printf("Value %d is prime.\n", a[i]); else printf("Value %d is not prime.\n", a[i]); return 0; } macbook:make_project> macbook:make_project> ls db Makefile supps.c db.c parts.c supps.h db.h parts.h example_makefile README.txt macbook:make_project> cat Makefile db: db.o supps.o parts.o echo "make db" ; gcc db.o supps.o parts.o -o db db.o: db.c db.h supps.h parts.h echo "make db.o" ; gcc -c db.c supps.o: supps.c supps.h echo "make supps.o" ; gcc -c supps.c parts.o: parts.c parts.h echo "make parts.o" ; gcc -c parts.c macbook:make_project> make echo "make db.o" ; gcc -c db.c make db.o echo "make supps.o" ; gcc -c supps.c make supps.o echo "make parts.o" ; gcc -c parts.c make parts.o echo "make db" ; gcc db.o supps.o parts.o -o db make db macbook:make_project> vi Makefile macbook:make_project> make make: `db' is up to date. macbook:make_project> touch supps.c macbook:make_project> ls -l supps.c -rw-r--r-- 1 mweeks staff 747 Nov 17 18:30 supps.c macbook:make_project> make echo "make supps.o" ; gcc -c supps.c make supps.o echo "make db" ; gcc db.o supps.o parts.o -o db make db macbook:make_project> macbook:make_project> exit Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. Script done on Mon Nov 17 18:39:57 2025