Very ANNOYING Problem - Please Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Very ANNOYING Problem - Please Help
# 1  
Old 03-12-2008
Very ANNOYING Problem - Please Help

Hey Guys

I have an extremely annoying problem with regular expressions! At this point i believe the command 'read' is causing the problem due to the carriage return it places once its done.

I have an continuous loop until the input is correct: (After initial read statement)

Code:
while [ 0 ]
        do
                if [[ "$word" == [a-z]+ ]]
                then
                        word=$(echo $word | tr "[A-Z]" "[a-z]")
                        encrypted=$(echo $word | tr "[a-z]" "-")
                        display $encrypted $word
                        break
                else
                        echo "Please enter a word consisting of only the letters a-z."
                        read word
                fi
        done

Whats highlighted in bold is the problem. Every time it reaches it, nothing is allowed ! Not even if the input is completely valid as in:

abcd

What i want it to do is accept ONLY a-z characters and nothing else - no spaces either. In theory it should work however in practice i really do believe the 'read' command is giving me the trouble. Maybe a chop-esque function is required such as the one in perl.

I hope you guys can help! Thank You. -shell is BASH
# 2  
Old 03-12-2008
Well I'm not a super bash expert, but that does what I guessed it might...
Code:
bash-2.03$ x="abc"
bash-2.03$ [[ $x == [a-z]+ ]] && echo it matches
bash-2.03$ x="d+"
bash-2.03$ [[ $x == [a-z]+ ]] && echo it matches
it matches
bash-2.03$

# 3  
Old 03-12-2008
Yeah, it seems so pointless ... Either the syntax is wrong or the guys behind the development of BASH got this one slightly wrong ...

I mean what i can do is individually check each character but its excessive code - 5 lines compared with 1. So if the experts can give me some advice, it would be much appreciated.

Thanks.
# 4  
Old 03-12-2008
Hi.

The alternate syntax seems to work:
Code:
#!/bin/bash3 -

# @(#) s1       Demonstrate extended glob matching.
# See man bash "Pattern matching" and extglob shopt.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1)

x="abc"
if [[ $x == [a-z]+ ]]
then
  echo " Matched trailing +."
fi

shopt -s extglob
if [[ $x == +([a-z]) ]]
then
  echo " Matched leading +."
fi

exit 0

Producing:
Code:
% ./s1
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 3.00.16(1)-release
 Matched leading +.

Best wishes ... cheers, drl
# 5  
Old 03-12-2008
Hey drl,

That does not seem to work on my end, possibly because your shell is bash3 but im not too sure of the difference between it and bash. I tried using the reverse syntax but no luck there, i get a few errors in doing so.

It does look like I'm going to have to use some longer code - just seems so silly that this little bug (if thats what it actually is) is causing me grief lol. Thanks for your help though.
# 6  
Old 03-12-2008
Hi.

What shell are you using? ... cheers, drl
# 7  
Old 03-12-2008
GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Thats the one I'm using at the moment.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I get out of the annoying > in bash???

Occasionally I make a mistake in my shell that results in there being a > for the prompt instead of the normal $. Today I accidentally left off a " in a sed command, sed s/\"//g" infile > outfile and then I get $ sed s/\"//g" infile > outfile > > I have never figured out how to get... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

PERL annoying scope problem

Hello, I met a problem with following code: #!/usr/bin/perl -w # test.pl use strict; use diagnostics; use DBI; my $dbh = DBI->connect( "DBI:mysql:BibleBook","yifangt","password") or die("Cannot connect: $DBI::errstr"); my $sql = qq(SELECT * FROM library WHERE isbn =... (2 Replies)
Discussion started by: yifangt
2 Replies

3. UNIX for Advanced & Expert Users

Annoying in VI editor

Dear all, I try to search " ( double quote ) in a file using vi editor, I gave in the command mode /" it supposed to take to me to all the occurnces of " instead in some places it is taking me to different character.! It happens with some other characters in that file.... can you... (5 Replies)
Discussion started by: shahnazurs
5 Replies

4. Shell Programming and Scripting

lack of understanding > annoying error

I'm working on a script I wrote called backup.sh when I run it like this: . ./backup.sh I get this error: ksh: ./backup.sh: no closing quote when I run it this way: backup.shI get this error: backup.sh: 28: Syntax error: end of file unexpected (expecting "fi")I looked through the code over... (21 Replies)
Discussion started by: jzacsh
21 Replies

5. Shell Programming and Scripting

Writing an annoying popup window

Hi, I work for Xerox. As a new guy, I was recently pranked by the resident Solaris guru.:cool: This is a celebrated event. I must now prank back in an equally flawless fashion. I wish to get back to him by writing a script that will generate an annoying popup randomly, a small window that... (1 Reply)
Discussion started by: orchus
1 Replies

6. Post Here to Contact Site Administrators and Moderators

Annoying tooltips

Hi Is there any way to turn off the (often ridiculously big) tooltips that are displayed when hovering over a topic in a topic list? It's driving me nuts. Thx. J (1 Reply)
Discussion started by: jgrogan
1 Replies

7. Solaris

annoying problem with nis

This is my home set up I have 2 solaris boxes at home. One is a nis server and one is client. everytime I start the client without server, it will hang permanently looking for for nis server. is there a way to get around this? Can you set timeout the nis client? I use nis becuase my... (4 Replies)
Discussion started by: congngo
4 Replies

8. UNIX for Dummies Questions & Answers

a very annoying problem

hi i got fbsd here,when i try to start my X server as an user I got hte following error. Fatal server error: xf86OpenConsole: Server must be running with root permissions You should be usig Xwrapper to start the server or xdm. We strongly advise against making the server SUID root! But... (2 Replies)
Discussion started by: Stormpie
2 Replies
Login or Register to Ask a Question