ebfbcff6a14fcda2e61ca5ae0919c4c66d50b0cd
[feisty_meow.git] / scripts / files / spaces_to_underscores.sh
1 #!/bin/bash
2
3 # takes names given to it and replaces any spaces or other gnarly characters with underscores.
4
5 #hmmm: this starts to look like a useful function that the bracket fixer could also use.
6
7 if [ $# -lt 1 ]; then
8   echo "This script requires one or more file names whose names should be fixed."
9   echo "Any spaces or single-quote characters will be stripped out in a useful way."
10   exit 1
11 fi
12
13 while [ $# -gt 0 ]; do
14   file="$1"; shift
15   newname="$(echo "$file" | tr ' ' '_' | tr -d "'" | sed -e 's/\([0-9]\)_\./\1./g' )"
16   if [ "$file" != "$newname" ]; then
17     # we've effected a name change, so let's actually do it.
18     echo "moving '$file' => '$newname'  "
19     mv "$file" "$newname"
20   fi
21 done
22