bash - regular expression approach

I just found this in the net while reading and browsing about bash, and I wanted to take this notes for my own sake :D.


#! /bin/bash

VARIABLE="Let's test this string!"

# This is for regular expressions:
if [[ "$VARIABLE" =~ "Let's.*ring" ]]
then
    echo "matched"
else
    echo "nope"
fi

# And here we have Bash Patterns:
if [[ "$VARIABLE" == L*ing! ]]
then
    echo "matched"
else
    echo "nope"
fi

Comments

Popular posts from this blog

Using sed with backreference as the replacement pattern

Use Shell Editor for Eclipse for editing bash, ksh, csh in Unix/Linux system

LVM: How to remove a volume using pvremove