Logo

Short snippets for bash

Here comes a little toolbox, which is mainly on my homepage, because it's a convenient way to have it availiable.
We start with a simple one. The ls-command is a little annoying to use even for some simple tasks. One of those is to print the subdirectories of the current directory. Using the find-command does the trick:
find -type d -maxdepth 1 | grep -v "\./\."
Next is a slighly longer one. Is offers the often wanted service to convert a filename to lower case
#!/bin/sh
while [ $# -ne 0 ]
do
  temp=`echo $1 | tr A-Z a-z`
  if [ $temp != $1 ]; then
    mv "$1" "$temp"
  fi
  shift
done
Everyone who uses the c programming language knows the situation of reading somebody else's code. And often it is no fun at all because of this disgusting style of code formatting. Well, three little tools could be helpfull.
The next script ensures proper formatted code with unix style newlines, and expanded tabs.
#!/bin/sh
while [ $# -ne 0 ]
do
  dos2unix -o $1
  indent -l200 -bad -bap -bbb -bli0 -npcs $1
  expand $1
  shift
done