Table of Contents
Bash Scripting
Resources
Useful Tricks
Existence of a Directory
if [ -z "`ls the/directory`" ]; then echo empty; fi
Getting the First Word in a String
Examples, using wc
wc_count=`wc -l SOMETHING | cut -d' ' -f1`
or
wc_count=`wc -l SOMETHING | awk '{ print $1 }'`
or
wc_count=`wc -l SOMETHING | (read X Y; echo $X)`
or
wc_count=`wc -l SOMETHING | sed -e 's/ .*//'`
or
wc_count=`wc -l SOMETHING` wc_count=${wc_count% SOMETHING}
or
function first { echo $1 } wc_count=$(first $(wc -l SOMETHING))