Showing posts with label zsh. Show all posts
Showing posts with label zsh. Show all posts

2012-08-17

How to check if a variable contains a string

string="this string contains a test substring"

if [[ "$string" == *test* ]]
then
        print "substring found"
fi 
 

2012-04-12

ZSH substr

One handy shortcut for getting all the characters except the first 2:

SHORTSTRING=$LONGSTRING[3,-1]

The negative offset is relative to the end of the string.