Bash - The Bourne Shell
Bash is my preferred Unix shell.
- If you want to loop over all the files in a directory and do something with each file:
for i in /usr/local/lib/*.so; do echo $i; done - If you have a list of files in the current directory whose case must be made consistent (in this case to lower-case).
for i in `ls`; do mv $i `echo $i | tr '[A-Z]' '[a-z]'`; done - Counting:
for i in $(seq 1 100); do echo $i; done - Looping:
for i in dog cat snake; do echo $i; done - Renaming tons of files using find, sed and sh:
find . -name "*.old" | sed -e 's/.*/mv & &/' -e 's/old$/new/' | sh - Setting your default LANG and LC_CTYPE:
export LANG="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_ALL=""
For more bash tips see deadman.org's bash tips page.