Unknown
Unknown

Reputation: 676

Grep .html Syntax

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

Answers (2)

Unknown
Unknown

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

Gilles Quénot
Gilles Quénot

Reputation: 185005

echo tester.html | grep -q '\.html$' && echo "MATCH" || echo >&2 "NO MATCH"

or in

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

Related Questions