![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with dd command or maybe AFS problem | Anta | Shell Programming and Scripting | 0 | 08-25-2006 10:10 AM |
| annoying vi yank word + delete all question | umen | UNIX for Dummies Questions & Answers | 4 | 03-20-2006 08:46 AM |
| SSH Problem auth problem | budrito | UNIX for Advanced & Expert Users | 1 | 03-17-2004 10:12 AM |
| a very annoying problem | Stormpie | UNIX for Dummies Questions & Answers | 2 | 04-24-2002 12:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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
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. Thanks. |
|
|||||
|
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 Code:
% ./s1 (Versions displayed with local utility "version") Linux 2.6.11-x1 GNU bash 3.00.16(1)-release Matched leading +. |
|
||||
|
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. |
![]() |
| Bookmarks |
| Tags |
| linux, regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|