head-1/dev/hdc# head: cannot open '/dev/hdc' for reading: No medium found# (No disc in the drive.)# head: error reading '/dev/hdc': Input/output error# (There is a disk in the drive, but it can't be read;#+ possibly it's an unrecorded CDR blank.) # Stream of characters and assorted gibberish# (There is a pre-recorded disk in the drive,#+ and this is raw output -- a stream of ASCII and binary data.)# Here we see the wisdom of using 'head' to limit the output#+ to manageable proportions, rather than 'cat' or something similar.# Now, it's just a matter of checking/parsing the output and taking#+ appropriate action.
#!/bin/bash# music.sh# Music without external files# Author: Antonio Macchi# Used in ABS Guide with permission.# /dev/dsp default = 8000 frames per second, 8 bits per frame (1 byte),#+ 1 channel (mono)duration=2000# If 8000 bytes = 1 second, then 2000 = 1/4 second.volume=$'\xc0'# Max volume = \xff (or \x00).mute=$'\x80'# No volume = \x80 (the middle).functionmknote () # $1=Note Hz in bytes (e.g. A = 440Hz ::{ #+ 8000 fps / 440 = 16 :: A = 16 bytes per second)for t in`seq0 $duration`dotest $(( $t % $1 )) =0&&echo-n $volume ||echo-n $mutedone}e=`mknote49`g=`mknote41`a=`mknote36`b=`mknote32`c=`mknote30`cis=`mknote29`d=`mknote27`e2=`mknote24`n=`mknote32767`# European notation.echo-n"$g$e2$d$c$d$c$a$g$n$g$e$n$g$e2$d$c$c$b$c$cis$n$cis$d \$n$g$e2$d$c$d$c$a$g$n$g$e$n$g$a$d$c$b$a$b$c">/dev/dsp# dsp = Digital Signal Processorexit# A "bonny" example of an elegant shell script!