I am trying to write a Kornshell function that takes a string parameter which represents a filename or directory name. The function checks to see if there are any spaces in the filename or directory name and then replaces the spaces with an underscore. The returned value is a filename or directory name without any spaces. Thanks for any suggestions you may have.
#! /bin/ksh
result=""
differ=0
function repspace
{
differ=0
echo $1 | grep -q " "
if [ $? -eq 0 ] ; then
result=`echo $1 | sed 's/ /_/g'`
differ=1
fi
}
for file in *.shl
do
repspace $file
if [ differ -eq 1 ] ; then
mv $file $result
fi
done