Reputation: 676
I'm very new to bash so I apologize if this is a dumb question.
I'm trying to write a script that takes a file and tests to see if it ends in html. Here is my code:
echo tester.html | grep -E '[^ ]*[.html]'
Yet it echos every input I give it, how do I fix it?
Upvotes: 0
Views: 145
Reputation: 676
I've solved it with the help of sputnick.
Here it is:
echo tester.html | grep -E *html
and this works,
thanks all.
Upvotes: 0
Reputation: 185005
echo tester.html | grep -q '\.html$' && echo "MATCH" || echo >&2 "NO MATCH"
or in bash
x=tester.html
[[ $x == *html ]] && echo "MATCH" || echo >&2 "NO MATCH"
&&
& ||
boolean syntax is a shorcut for if condition; then something; else something_else; fi
, see http://mywiki.wooledge.org/BashGuide/TestsAndConditionals
NOTE
- using []
in a regex means character class (a set of characters)
Upvotes: 1