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

case "$dec" in<br />

[0−9]*) ;; # number ok<br />

*) continue;; # error: ignore<br />

esac<br />

!<br />

}<br />

# Print all conversions in one line.<br />

# ==> 'here document' feeds command list to 'bc'.<br />

echo `bc More error checking for illegal input would be useful.<br />

shift<br />

done<br />

if [ $# −gt 0 ]<br />

then<br />

PrintBases "$@"<br />

else<br />

while read line<br />

do<br />

PrintBases $line<br />

done<br />

fi<br />

# read from stdin<br />

An alternate method of invoking bc involves using a here document embedded within a command<br />

substitution block. This is especially appropriate when a script needs to pass a list of options and<br />

commands to bc.<br />

variable=`bc

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

Saved successfully!

Ooh no, something went wrong!