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.

echo "one two three" | read a b c<br />

# Try to reassign a, b, and c.<br />

echo<br />

echo "a = $a" # a = aaa<br />

echo "b = $b" # b = bbb<br />

echo "c = $c" # c = ccc<br />

# Reassignment failed.<br />

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

# Try the following alternative.<br />

var=`echo "one two three"`<br />

set −− $var<br />

a=$1; b=$2; c=$3<br />

echo "−−−−−−−"<br />

echo "a = $a" # a = one<br />

echo "b = $b" # b = two<br />

echo "c = $c" # c = three<br />

# Reassignment succeeded.<br />

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

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

# Note also that an echo to a 'read' works within a subshell.<br />

# However, the value of the variable changes *only* within the subshell.<br />

a=aaa<br />

b=bbb<br />

c=ccc<br />

# Starting all over again.<br />

echo; echo<br />

echo "one two three" | ( read a b c;<br />

echo "Inside subshell: "; echo "a = $a"; echo "b = $b"; echo "c = $c" )<br />

# a = one<br />

# b = two<br />

# c = three<br />

echo "−−−−−−−−−−−−−−−−−"<br />

echo "Outside subshell: "<br />

echo "a = $a" # a = aaa<br />

echo "b = $b" # b = bbb<br />

echo "c = $c" # c = ccc<br />

echo<br />

exit 0<br />

Using "suid" commands within scripts is risky, as it may compromise system security. [62]<br />

Using shell scripts for CGI programming may be problematic. Shell script variables are not "typesafe", and<br />

this can cause undesirable behavior as far as CGI is concerned. Moreover, it is difficult to "cracker−proof"<br />

shell scripts.<br />

Bash does not handle the double slash (//) string correctly.<br />

Bash scripts written for Linux or BSD systems may need fixups to run on a commercial UNIX machine. Such<br />

scripts often employ GNU commands and filters which have greater functionality than their generic UNIX<br />

counterparts. This is particularly true of such text processing utilites as tr.<br />

Chapter 32. Gotchas 331

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

Saved successfully!

Ooh no, something went wrong!