#!/bin/bash
#

if [ -z "$1" ]; then
	echo "Parameter missed"
	exit 1
fi

# directories first
#
find "$1" -name "* *" -type d -print0 | \
  while read -r -d $'\0' f; do mv -v "$f" "${f// /_}"; done

# files
#
find "$1" -name "* *" -type f -print0 | \
  while read -r -d $'\0' f; do mv -v "$f" "${f// /_}"; done 

exit $?
