Tuesday, August 4, 2009

simple bash

A good and compact Bash reference

Another good introduction. More complete.

A Very Simple example:


#!/bin/bash

i=0
while [ $i -lt 400 ]; do
printf "%i : %b\n" "$i" "\0$i"
let "i++"
done


Getting the script path


SCRIPT_PATH="${BASH_SOURCE[0]}";
if([ -h "${SCRIPT_PATH}" ]) then
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
popd > /dev/null