/ Published in: Bash
Using a (faster) case structure to do bash built-in pattern matching. See Bash hackers for more information. Thanks to gnashley for the snippet.
Expand |
Embed | Plain Text
#!/bin/sh thisString="1 2 3 4 5" searchString="1 2" # if you single quote your input, you could do this # searchString=$1 case $thisString in # match exact string "$searchString") echo yep, it matches exactly;; # match start of string "$searchString"*) echo yep, it matches at the start ;; # match end of string *"$searchString") echo yep, it matches at the end ;; # searchString can be anywhere in thisString *"$searchString"*) echo yep, it matches in the middle somewhere ;; *) echo nope ;; esac
You need to login to post a comment.
