Talk:TIP lowercase files and directories
From Gentoo Linux Wiki
Bug: reversed test
The filename in the tests should be quoted, to allow for spaces. Also, it doesn't affect the output, but I think this is a typo:
| Code: original |
|
#code never gets here... can't be -f and -d at the same time!
continue
</nowiki></pre> code> |
It should be the opposite way:
| Code: reversed test |
|
#code gets here for pipes etc
continue
</nowiki></pre> code> |
Also, since you are essentially using the same code in the loop, the whole thing could be written as:
| File: lowerit.sh |
|
if [ ! $1 ]; then echo "Not enough arguments. Try $0 -h for options."
exit 1
fi case "$1" in "-f"| "-d" ) test="[[ $1 \"\$x\" ]]" ;;
"-a" ) test='[[ ( -f "$x" || -d "$x" ) ]] ;;
"-h" )
echo "-----------------------------------------------------------"
echo "lowercase v1.0 - Convert files or directories to lowercase."
echo "-----------------------------------------------------------"
echo "Usage: $0 <option>"
echo
echo "Options:"
echo " -f = All files in current directory."
echo " -d = All directories in current directory."
echo " -a = All files AND directories in current directory."
echo " -h = This help screen."
echo
echo "Notes: If a lowercase directory already exists that has the same"
echo " name as the uppercase directory, the uppercase will be"
echo " MOVED to the lowercase directory without confirmation."
exit
;;
* )
echo "$0: Invalid argument. Try $0 -h for help."
exit 1;;
esac
for x in * do
if eval "$test" ; then
convert=`echo $x | tr '[A-Z]' '[a-z]'`
if [ "$convert" != "$x" ]; then
mv -i "$x" "$convert"
fi
else
continue
fi
done </nowiki></pre> code> |
- Ajasen 05:08, 25 December 2005 (GMT)
