3 # takes names given to it and replaces any spaces or other gnarly characters with underscores.
5 #hmmm: this starts to look like a useful function that the bracket fixer could also use.
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."
13 while [ $# -gt 0 ]; do
15 # first turn spaces into underscores. then process characters we don't want
16 # in names. then translate multiple underscores into just one. then turn
17 # number followed by underscore into just number (?). then translate
18 # underscore dash underscore into just dash.
19 newname="$(echo "$file" | tr -s ' ' '_' | tr -d "\$\!|@&#%}{)(][\\\~',:?><\"" | sed -e 's/__/_/g' | sed -e 's/\([0-9]\)_\./\1./g' | sed -e 's/_-_/-/' )"
20 if [ "$file" != "$newname" ]; then
21 # we've effected a name change, so let's actually do it.
22 echo "'$file' => '$newname'"