The noise at the end is some feedback from my amp. I felt this week I made some progress, but I think I can do even better next week. My fingers were pretty sore from playing earlier today so I hope that building up my callouses will help some.
Useful chapter. It's complicated to keep track of the different ways that parameters can be parsed. Now I see why a cookbook is a useful format for bash. Lots of syntax gotchas.
String manipulation operators are cool, but seem hard to remember also.
Nice chapter. I've been looking for something similar to nohup for a long time. I've actually resorted to using cron at times for one-off long running tasks. nohup is going to save me a lot of trouble :)
Complete. The select function in 3.7 is pretty cool. I didn't know that existed.
I got the following error when I tried 3.6. Not sure how to fix it because they kind of just put a big script in there without much explanation. Otherwise the homework went well.
# cookbook filename: func_choose
# Let the user make a choice about something and execute code based on
# the answer
# Called like: choose <default (y or n) > <prompt> <yes action> <no action>
# e. g. choose "y" \
# "Do you want to play a game?" \
# /usr/games/GlobalThermonucularWar \
# ' printf "%b" "See you later Professor Falkin. "' >&2
# Returns: nothing
function choose {
local default="$1"
local prompt="$2"
local choice_yes="$3"
local choice_no="$4"
local answer
read -p "$prompt" answer
[ -z "$answer" ] && answer="$default"
case "$answer" in
[ yY1] ) exec "$choice_yes"
# error check
;;
[ nN0] ) exec "$choice_no"
# error check
;;
* ) printf "%b" "Unexpected answer ' $answer' ! " >&2 ; ;
esac
} # end of function choose
choose y "choose one" {echo "yes"} {echo "no"}
$./func_choose
$./func_choose: line 19: syntax error near unexpected token `yY1]'
I couldn't get 2.12 to work, Skipping a Header in a File. tail kept trying to open the file '+2' and gave an error (see below).
I also skipped a couple towards the end like 2.19 and 2.20. The rest of the examples worked well, and I learned more than I expected to given it's the first chapter.
kevin@heater:~/bashtest2$ tail +2 /tmp/ls.out
tail: cannot open `+2' for reading: No such file or directory
==> /tmp/ls.out <==
k
s
a
d
f
g
h
j
k
s
kevin@heater:~/bashtest2$ tail /tmp/ls.out +2
==> /tmp/ls.out <==
k
s
a
d
f
g
h
j
k
s
tail: cannot open `+2' for reading: No such file or directory
1.4 The operator can be either + or -, depending on the value of b. If b is greater than zero, it's added to a. If b is less than zero, it's subtracted from a. The result is the same as adding the absolute value of b to a.
1.5 If it's applicative order, it will execute the arguments of test first. That means it will execute (p), which will result in an infinite loop. If it's normal order, the if statement will be executed first, and will return zero immediately. (p) will never be executed.
1.6 'new-if' doesn't get a chance to evaluate because its arguments are executed first and hit the max recursion depth before returning a value. That's why if is provided as a special form.
;;;;;;;;;;;;;;;;;;;;;
;;; 1.3:
;;;;;;;;;;;;;;;;;;;;;
(define (ss a b c)
(cond ((and (< a b) (< a c)) (+ (* b b) (* c c)))
((and (< b a) (< b c)) (+ (* a a) (* c c)))
(else (+ (* a a) (* b b)))))
(ss 1 2 3)
;;;;;;;;;;;;;;;;;;;;;;;;
;;; 1.7:
;;;;;;;;;;;;;;;;;;;;;;;;
(define (good-enough? old-guess new-guess)
(< (abs (/ (- old-guess new-guess) new-guess)) .001))
(define (abs x)
(if (> x 0)
x
(* x -1)))
(define (sqrt x)
(sqrt-iter 0.1 1.0 x))
;;;;;;;;;;;;;;;;;;;;;
;;; 1.8:
;;;;;;;;;;;;;;;;;;;;
(define (cubert x)
(cubert-iter 0.1 1.0 x))
(define (cubert-iter old-guess new-guess x)
(if (good-enough? old-guess new-guess)
new-guess
(cubert-iter new-guess (improve-cube new-guess x)
x)))
(define (improve-cube guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))
(define (good-enough? old-guess new-guess)
(< (abs (/ (- old-guess new-guess) new-guess)) .001))
(define (abs x)
(if (> x 0)
x
(* x -1)))
(define (sqrt-iter old-guess new-guess x)
(if (good-enough? old-guess new-guess)
new-guess
(sqrt-iter new-guess (improve new-guess x)
x)))