[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Substring search in dash [ _NOT_ bash ] shell



On Mon, Sep 26, 2016 at 10:39:59AM -0500, Richard Owlett wrote:
> #      string if [ "`hostname`" = bob ]; then echo bob.cfg; fi
> 
> I need for the case when evaluates to marybobsam .
> I can find examples in bash shell, but I need dash.

Are you asking how to check for the substring "bob" in your input,
in POSIX sh?  Use case, and a glob:

case $input in
  *bob*) echo "Bob found." ;;
esac

case $(hostname) in
  *bob*) echo "I must be a Bob." ;;
esac


Reply to: