Bash script to find out whether the current directory has character '.' at the end

I want a script to find out whether the current directory, has character '.' at the end of each level of subdirectories. e.g.,
-if the current directory is /root/appl./test , it should return true
-if the current directory is /root/appl/test. , it should return true
-if the current directory is /root/appl/test./ , it should return true
-if the current directory is ./root/appl/test./ , it should return false

thanks
shimsha
shimshaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NovaDenizenCommented:
Uncomment the echo lines to see how it works.

#!/bin/bash

DIR=`pwd`/
#echo DIR is $DIR
echo $DIR | grep -q \\./ -
RES=$?
#echo RES is $RES
exit $RES
0
TintinCommented:
NovaDenizen.

Your code would return true for the last example, which should be false.

Here's a version that works for the sample cases:

#!/bin/sh

pwd | grep -q "^/.*\."

if [ $? -eq 0 ]
then
     echo "cwd has ."
else
     echo "cwd has no ."
fi
0
shimshaAuthor Commented:
Thanks for the scripts.
This script returns true when the directory name has spaces in the middle of th name. I want to check the character '.' only at the end of directory names. So,
-if the current directory is /root/appl.test/test , it should return false
-if the current directory is /root/appl./test , it should return true

thanks,
shimsha
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

TintinCommented:
Assuming you're using pwd to get the cwd, then NovaDenizen's suggestion will work fine for you.
0
NovaDenizenCommented:
What is the deal with the fourth example?
/root/appl./test  true
/root/appl/test. true
/root/appl/test./ true
./root/appl/test./ false

How can the current directory possibly start with a '.' like in the fourth example?

Also, the 'test.' directory of the fourth example ends with a period, so it should return true according to your description.

Your question reads:
> I want a script to find out whether the current directory, has character '.' at the end of each level of subdirectories.
Well, none of your examples has a '.' at the end of each level of subdirectories.  Perhaps you meant to say "any level of subdirectories" instead?
0
da99rmdCommented:
I think this solved your problem, I devided the regexp in 2 to make it easier to understand.

#!/bin/bash
echo `pwd` |  egrep -q '^[^\.]' |  egrep -q '\.(/|$)'
if [ $? -eq 0 ]
then
     echo "cwd has ."
else
     echo "cwd has no ."
fi
#end

/R
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TintinCommented:
da99rmd

UUOE

echo `pwd`
0
da99rmdCommented:
What ?
/R
0
TintinCommented:
Google is your friend.  
0
TintinCommented:
Whoops.  I did a search for UUOC (which is directly related), but UUOE only has an obscure reference.

UUOE - Useless Use of Echo

echo `pwd`

is the same as:

pwd
0
da99rmdCommented:
hehe, its a habit i use echo for everything =)

/R
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.