Click to See Complete Forum and Search --> : If, then, else or loop? help


ncsuapex
02-23-2006, 02:34 PM
I have a script that changes all file extensions from .jpg to .JPG. I have written the script to go from .JPG to .jpg as well. What I need help with is. How would I edit the script to do either convert them from .jpg to .JPG or .JPG to .jpg


My current script is:


#!/bin/bash
# I just run the script and make sure I put a # at the start of the line I don't # need.


for i in *.jpg; do j=`basename "$i" .jpg`; mv -v "$i" "$j.JPG"; done

for i in *.JPG; do j=`basename "$i" .JPG`; mv -v "$i" "$j.jpg"; done


How would I make it check for jpg and change it to JPG, if there are no jpg, then it needs to check for JPG and then convert them to jpg.

Thanks

ph34r
02-23-2006, 02:57 PM
add an argument to how you call the script

if $1 is null, exit and explain the arg it expects

if $1 == upper then
do the upper case version
else if $1 == lower
do the lower case version
else
complain about an arg being there, but not being upper or lower

ncsuapex
02-23-2006, 04:11 PM
I just created 2 seperate scripts, one to make it lower case to upper, one to make it upper to lower. Thanks.