testingubuntu
May 22nd, 2005, 01:17 PM
I have a bash script i use to create thumbnails and stuff
I am trying to protect against incorrect directories but it seems that it wont test the dir the way i want it to
here is the script
I'm using the 4th command or the "Test"
#!/bin/bash
#*******************************************#
# Convert.sh #
# Written By: James Lawrence #
# May 20 2005 #
# #
# create thumbnails of images #
#*******************************************#
############
# Varibles #
############
user=`whoami`
locate="/" # the location the user types in for a directory
images="/home/$user" #default directory to start in
#############
# Functions #
#############
# Now ask the user where the JPG images are
function CONVERTJPG
{
read -p "Type the path to the jpegs [$images]:" locate
cd $locate
for img in $(ls *.[jJ][pP][gG])
do
convert -sample 25%x25% $img thumb-$img # Create the thumbnails
done
}
# Now ask the user where the PNG images are
function CONVERTPNG
{
read -p "Type the path to the png images [$images]:" locate
cd $locate
for img in $(ls *.[pP][nN][gG])
do
convert -sample 25%x25% $img thumb-$img # Create the thumbnails
done
}
################################################## ##############
function TEST # for testing new functions
{
read -p "Type the path to the jpegs [$images]:" locate
if cd "$locate" 2>/dev/null; then
echo "Now in $locate"
else
echo "Wrong Directory Dude! can't change to $locate"
fi
for img in $(ls *.[jJ][pP][gG])
do
convert -sample 25%x25% $img thumb-$img # Create the thumbnails
done
}
######################
# a little interface #
######################
selection=
until [ "$selection" = "0" ]; do
echo ""
echo "Options..."
echo " 1 - Seek n Convert Jpg's"
echo " 2 - Seek n Convert Png's"
echo " 3 - Location"
echo " 4 - TEST"
echo " 0 - Close"
echo ""
echo -n "Enter a Number: "
read selection
echo ""
###################
# Cases selection #
###################
case $selection in
1 ) $(CONVERTJPG) ;;
2 ) $(CONVERTPNG) ;;
3 ) pwd ;;
4 ) $(TEST) ;;
0 ) exit ;;
* ) echo "Please enter 1, 2, 3 or 0"
esac
done
I am trying to protect against incorrect directories but it seems that it wont test the dir the way i want it to
here is the script
I'm using the 4th command or the "Test"
#!/bin/bash
#*******************************************#
# Convert.sh #
# Written By: James Lawrence #
# May 20 2005 #
# #
# create thumbnails of images #
#*******************************************#
############
# Varibles #
############
user=`whoami`
locate="/" # the location the user types in for a directory
images="/home/$user" #default directory to start in
#############
# Functions #
#############
# Now ask the user where the JPG images are
function CONVERTJPG
{
read -p "Type the path to the jpegs [$images]:" locate
cd $locate
for img in $(ls *.[jJ][pP][gG])
do
convert -sample 25%x25% $img thumb-$img # Create the thumbnails
done
}
# Now ask the user where the PNG images are
function CONVERTPNG
{
read -p "Type the path to the png images [$images]:" locate
cd $locate
for img in $(ls *.[pP][nN][gG])
do
convert -sample 25%x25% $img thumb-$img # Create the thumbnails
done
}
################################################## ##############
function TEST # for testing new functions
{
read -p "Type the path to the jpegs [$images]:" locate
if cd "$locate" 2>/dev/null; then
echo "Now in $locate"
else
echo "Wrong Directory Dude! can't change to $locate"
fi
for img in $(ls *.[jJ][pP][gG])
do
convert -sample 25%x25% $img thumb-$img # Create the thumbnails
done
}
######################
# a little interface #
######################
selection=
until [ "$selection" = "0" ]; do
echo ""
echo "Options..."
echo " 1 - Seek n Convert Jpg's"
echo " 2 - Seek n Convert Png's"
echo " 3 - Location"
echo " 4 - TEST"
echo " 0 - Close"
echo ""
echo -n "Enter a Number: "
read selection
echo ""
###################
# Cases selection #
###################
case $selection in
1 ) $(CONVERTJPG) ;;
2 ) $(CONVERTPNG) ;;
3 ) pwd ;;
4 ) $(TEST) ;;
0 ) exit ;;
* ) echo "Please enter 1, 2, 3 or 0"
esac
done