Results 1 to 3 of 3
#cat test.sh
if test $1 = '\[1*\]'
then
echo "Yes is a Matching Pattern"
else
echo "Not a Matching Patern"
fi
but this does not match for 1 , 11 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-03-2004 #1Just Joined!
- Join Date
- Oct 2004
- Posts
- 3
pattern matching - plz guide
#cat test.sh
if test $1 = '\[1*\]'
then
echo "Yes is a Matching Pattern"
else
echo "Not a Matching Patern"
fi
but this does not match for 1 , 11 or 111
it matches foronly 1*
also tried using the following
if [ $1 = [1*] ] - - > did not match for 11
if [ $1 -eq [1*] ] - - > it complains test.sh: line 2: [: [1*]: integer expression expected
Can any body tell me y the pattern matching is not hapening?
- 11-03-2004 #2Linux Guru
- Join Date
- Mar 2003
- Location
- Wisconsin
- Posts
- 1,907
How about
Double quotes instead of single quotes? I think you can safely remove the [] as well.Code:if test $1 = "1*"
JeremyRegistered Linux user #346571
"All The Dude ever wanted was his rug back" - The Dude
- 11-03-2004 #3No...you need the [...]. That is the bash construct for conditional testing.
Originally Posted by jeremy1701
Try this:
Are you trying to match any combination of 1's? This will only match a 1 with anything after it at all. I'm not sure how you would go about matching a pattern of 1's in bash, but I'll research it.Code:if [ $1 = [1]* ]; then echo "It matches!"; else echo "No match!"; fi
Edit: That doesn't work, either. I don't know how to go about doing this....
"Time is an illusion. Lunchtime, doubly so."
~Douglas Adams, The Hitchhiker's Guide to the Galaxy


Reply With Quote
