27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

read ready<br />

# Wait for input, $ready not used.<br />

echo; echo "Copying the source CD to $OF."<br />

echo "This may take a while. Please be patient."<br />

dd if=$CDROM of=$OF bs=$BLOCKSIZE<br />

# Raw device copy.<br />

echo; echo "Remove data CD."<br />

echo "Insert blank CDR."<br />

echo "Press ENTER when ready. "<br />

read ready<br />

# Wait for input, $ready not used.<br />

echo "Copying $OF to CDR."<br />

cdrecord −v −isosize speed=$SPEED dev=0,0 $OF<br />

# Uses Joerg Schilling's "cdrecord" package (see its docs).<br />

# http://www.fokus.gmd.de/nthp/employees/schilling/cdrecord.html<br />

echo; echo "Done copying $OF to CDR on device $CDROM."<br />

echo "Do you want to erase the image file (y/n)? " # Probably a huge file.<br />

read answer<br />

case "$answer" in<br />

[yY]) rm −f $OF<br />

echo "$OF erased."<br />

;;<br />

*) echo "$OF not erased.";;<br />

esac<br />

echo<br />

# Exercise:<br />

# Change the above "case" statement to also accept "yes" and "Yes" as input.<br />

exit 0<br />

Example A−7. Collatz series<br />

#!/bin/bash<br />

# collatz.sh<br />

# The notorious "hailstone" or Collatz series.<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# 1) Get the integer "seed" from the command line.<br />

# 2) NUMBER

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!