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

LVM: How to remove a volume using pvremove

Using Oracle 11g thru VirtualBox appliance in Mac OS X Lion

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