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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

line 2<br />

EOF<br />

# OUTPUT:<br />

# line<br />

# 1<br />

# Thanks, S.C.<br />

exit 0<br />

[49] Filename expansion can match dotfiles, but only if the pattern explicitly includes the dot.<br />

~/[.]bashrc<br />

~/?bashrc<br />

~/.[b]ashrc<br />

~/.ba?hrc<br />

~/.bashr*<br />

# Will not expand to ~/.bashrc<br />

# Neither will this.<br />

# Wild cards and metacharacters will not expand to a dot in globbing.<br />

# Will expand to ~./bashrc<br />

# Likewise.<br />

# Likewise.<br />

# Setting the "dotglob" option turns this off.<br />

# Thanks, S.C.<br />

[50] This has the same effect as a named pipe (temp file), and, in fact, named pipes were at one time used in<br />

process substitution.<br />

[51] Indirect variable references (see Example 35−2) provide a clumsy sort of mechanism for passing<br />

variable pointers to functions.<br />

#!/bin/bash<br />

ITERATIONS=3 # How many times to get input.<br />

icount=1<br />

my_read () {<br />

# Called with my_read varname,<br />

# outputs the previous value between brackets as the default value,<br />

# then asks for a new value.<br />

local local_var<br />

echo −n "Enter a value "<br />

eval 'echo −n "[$'$1'] "' # Previous value.<br />

read local_var<br />

[ −n "$local_var" ] && eval $1=\$local_var<br />

}<br />

# "And−list": if "local_var" then set "$1" to its value.<br />

echo<br />

while [ "$icount" −le "$ITERATIONS" ]<br />

do<br />

my_read var<br />

echo "Entry #$icount = $var"<br />

let "icount += 1"<br />

echo<br />

done<br />

Appendix J. Copyright 444

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

Saved successfully!

Ooh no, something went wrong!