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.

echo "Testing \"strlen\" function:"<br />

str=123456789<br />

echo "\"str\" = $str"<br />

echo −n "Length of \"str\" = "<br />

strlen str<br />

echo<br />

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

# Exercise:<br />

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

# Add code to test all the other string functions above.<br />

exit 0<br />

Michael Zick's complex array example uses the md5sum check sum command to encode directory<br />

information.<br />

Example A−20. Directory information<br />

#! /bin/bash<br />

# directory−info.sh<br />

# Parses and lists directory information.<br />

# NOTE: Change lines 273 and 353 per "README" file.<br />

# Michael Zick is the author of this script.<br />

# Used here with his permission.<br />

# Controls<br />

# If overridden by command arguments, they must be in the order:<br />

# Arg1: "Descriptor Directory"<br />

# Arg2: "Exclude Paths"<br />

# Arg3: "Exclude Directories"<br />

#<br />

# Environment Settings override Defaults.<br />

# Command arguments override Environment Settings.<br />

# Default location for content addressed file descriptors.<br />

MD5UCFS=${1:−${MD5UCFS:−'/tmpfs/ucfs'}}<br />

# Directory paths never to list or enter<br />

declare −a \<br />

EXCLUDE_PATHS=${2:−${EXCLUDE_PATHS:−'(/proc /dev /devfs /tmpfs)'}}<br />

# Directories never to list or enter<br />

declare −a \<br />

EXCLUDE_DIRS=${3:−${EXCLUDE_DIRS:−'(ucfs lost+found tmp wtmp)'}}<br />

# Files never to list or enter<br />

declare −a \<br />

EXCLUDE_FILES=${3:−${EXCLUDE_FILES:−'(core "Name with Spaces")'}}<br />

# Here document used as a comment block.<br />

:

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

Saved successfully!

Ooh no, something went wrong!