retrieve directory name from a $file variable

Hi

I started this script, in which I would like to get the directory name where $file is located, and put it in a variable. I only want the name of the directory, not the path...

Can someone help ?

Cheers

Terence
#!/bin/sh
thumbdir=/Users/terencepires/Documents/Skydog/Images/for_web/thumb
 
for file in $(find . -type f -iname "*.jpg" -o -iname "*.tif" -o -iname "*.tiff" -o -name "*.gif"); do 
 
#imageMagick format and size conversion 
convert $file -quality 10 -resize 25% $thumbdir$file
done

Open in new window

LVL 1
terencepiresAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TintinConnect With a Mentor Commented:
Two better solutions are to do

find *

instead of

find .

or

file=`echo $file | sed "s/^..//"`

instead of

file=`echo $file | cut -c3-70`

0
 
ozoCommented:
directory=`dirname $file`
0
 
terencepiresAuthor Commented:
ok but it gives this :

./__Freddy_Lynxx
./__Flamin_Groovies
./__Eddie_and_Ze_Hot_Rods

I need to remove the ./ how can i do ?
0
 
terencepiresAuthor Commented:
ok I did it like this : file=`echo $file | cut -c3-70`

thanks anyway

Terence
0
All Courses

From novice to tech pro — start learning today.