I wrote a script today as follows:
echo "Enter a directory path"
read dir
for file in $dir/[!.]*;
do
f=`echo $file | sed 's/ /_/g'`
mv "${file}" "${f}"
done
Initially, the mv command was written as:
mv ${file} ${f}
But that line was throwing
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
I was able to use google to figure out that the variables needed to be wrapped in double quotes, but I still don't understand why doing so resolved the problem?
Thanks!