Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
labs:bash [2008/07/23 21:47] – created adminlabs:bash [2008/09/20 00:29] (current) admin
Line 1: Line 1:
 +====== Bash Scripting ======
  
 +===== Resources =====
 +
 +  * [[http://tldp.org/LDP/abs/html/|Advanced Bash Scripting Guide]]
 +
 +===== 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)) 
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0