11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

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

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

the Field-Array-Name per:<br />

Index-Array-Name[Line-Number * 2] : The "inode" field element.<br />

NOTE: This <strong>di</strong>stance may be either +11 or +12 elements.<br />

Index-Array-Name[(Line-Number * 2) + 1] : The "pathname" element.<br />

NOTE: This <strong>di</strong>stance may be a variable number of elements.<br />

Next line index pair for Line-Number+1.<br />

IndexListDoc<br />

IndexList()<br />

{<br />

local -a LIST # Local of listname passed<br />

local -a -i INDEX=( 0 0 ) # Local of index to return<br />

local -i Lidx Lcnt<br />

local -i if=0 of=0 # Default to variable names<br />

case "$#" in # Simplistic option testing<br />

0) return 1 ;;<br />

1) return 1 ;;<br />

2) : ;; # Poor man’s continue<br />

3) case "$1" in<br />

-if) if=1 ;;<br />

-of) of=1 ;;<br />

* ) return 1 ;;<br />

esac ; shift ;;<br />

4) if=1 ; of=1 ; shift ; shift ;;<br />

*) return 1<br />

esac<br />

# Make local copy of list<br />

case "$if" in<br />

0) eval LIST=\( \"\$\{$1\[@\]\}\" \) ;;<br />

1) LIST=( $(cat $1) ) ;;<br />

esac<br />

# Grok (grope?) the array<br />

Lcnt=${#LIST[@]}<br />

Lidx=0<br />

until (( Lidx >= Lcnt ))<br />

do<br />

if IsNumber ${LIST[$Lidx]}<br />

then<br />

local -i inode name<br />

local ft<br />

inode=Lidx<br />

local m=${LIST[$Lidx+2]} # Hard Links field<br />

ft=${LIST[$Lidx+1]:0:1} # Fast-Stat<br />

case $ft in<br />

b) ((Lidx+=12)) ;; # Block device<br />

c) ((Lidx+=12)) ;; # Character device<br />

*) ((Lidx+=11)) ;; # Anything else<br />

esac<br />

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

648

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

Saved successfully!

Ooh no, something went wrong!