Contents |
Calling a bash function when in a find
find . -name "*.xml" | while read i; do function "$i"; done
Checking for number of commandline arguments
EXPECTED_ARGS=1 E_BADARGS=65 if [ $# -ne $EXPECTED_ARGS ] then echo "Usage: `basename $0` {arg}" exit $E_BADARGS fi
Reference: http://www.linuxweblog.com/bash-argument-numbers-check
Use of the bash conditional
Refer to http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
Substring / String Length
Using build-in variables:
LEN=${#FILE} OLD_FILE=${FILE%.new}
Using expr (counts from 1, not from 0):
LEN=`expr length $FILE` CUTLEN=`expr $LEN - 5` OLD_FILE=`expr substr $FILE 1 $CUTLEN`
Further reading about shell parameter expansion: http://www.delorie.com/gnu/docs/bash/bashref_29.html
- Views -
Page -
Discussion -
View source -
History -
- Personal tools - Log in -
- Special - Special pages -
- Personal tools - Log in -
- Special - Special pages -