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 />

exit 0<br />

Example 35−3. Simple database application, using indirect variable referencing<br />

#!/bin/bash<br />

# resistor−inventory.sh<br />

# Simple database application using indirect variable referencing.<br />

# ============================================================== #<br />

# Data<br />

B1723_value=470<br />

B1723_powerdissip=.25<br />

B1723_colorcode="yellow−violet−brown"<br />

B1723_loc=173<br />

B1723_inventory=78<br />

# ohms<br />

# watts<br />

# color bands<br />

# where they are<br />

# how many<br />

B1724_value=1000<br />

B1724_powerdissip=.25<br />

B1724_colorcode="brown−black−red"<br />

B1724_loc=24N<br />

B1724_inventory=243<br />

B1725_value=10000<br />

B1725_powerdissip=.25<br />

B1725_colorcode="brown−black−orange"<br />

B1725_loc=24N<br />

B1725_inventory=89<br />

# ============================================================== #<br />

echo<br />

PS3='Enter catalog number: '<br />

echo<br />

select catalog_number in "B1723" "B1724" "B1725"<br />

do<br />

Inv=${catalog_number}_inventory<br />

Val=${catalog_number}_value<br />

Pdissip=${catalog_number}_powerdissip<br />

Loc=${catalog_number}_loc<br />

Ccode=${catalog_number}_colorcode<br />

echo<br />

echo "Catalog number $catalog_number:"<br />

echo "There are ${!Inv} of [${!Val} ohm / ${!Pdissip} watt] resistors in stock."<br />

echo "These are located in bin # ${!Loc}."<br />

echo "Their color code is \"${!Ccode}\"."<br />

break<br />

done<br />

echo; echo<br />

# Exercise:<br />

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

Chapter 35. Bash, version 2 356

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

Saved successfully!

Ooh no, something went wrong!