Re: does a variable contain...



Bruce Bowler wrote:

Imagine

var1=SomeValueThatComesFromElsewhere

Is there a way, in bash, to determine if the value in var1 contains the string "From"?

I suppose I could echo it into a temporary file and grep for "From" but that seems a little less than optimal. Is there a better way?

Thanks!
Bruce

case $var in
*From* ) echo "Eureka!" ;;
esac

Ed.
.



Relevant Pages

  • Re: :t and getting senile.
    ... how do you strip off the end of string such as a command line string so ... That's a csh feature also found in tcsh and zsh. ... With bash it's only available via the csh-like history ... bash-3.1$ echo a/b.c ...
    (comp.unix.shell)
  • Re: bash script call to dialog fails
    ... Here is the source code of the script which I tried. ... echo $menu_title ... Try adding this in place of $DIALOG to see how bash breaks the ... I can't find a way to make that string pass through the the operations you ask ...
    (comp.os.linux.development.apps)
  • Re: [opensuse] grep sed and awk question
    ... Given a string like this: ... echo v1 $v1 ... To contact the owner, e-mail: ...
    (SuSE)
  • Re: does a variable contain...
    ... On 07.05.2007, Bruce Bowler wrote: ... Is there a way, in bash, to determine if the value in var1 contains the ... string "From"? ...
    (comp.unix.shell)
  • Re: print command
    ... >> the last echo is to get the newline to print. ... Basically this is the bash for loop. ... My perl example was pretty bad: ... This prints the string "*" 80 times and sticks "\n" at the end. ...
    (Debian-User)