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
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.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
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 +.
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.
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)
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)
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)
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)
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
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)
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)
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)