How can I grep complex strings in variables?

后端 未结 4 1470
情歌与酒
情歌与酒 2021-02-03 22:06

I am trying to grep for a small string in a much larger string. Both strings are being stored as variables and here is a code example:

#!/bin/bash

long_str=$(m         


        
4条回答
  •  清歌不尽
    2021-02-03 22:48

    Another Bash-specific technique:

    if [[ $long =~ $short ]]    # regex match
    then
        echo "yes"
    fi
    

    But if you don't need the long string in a variable:

    if man man | grep $short; then ...
    

    but I'm assuming that was just for the purpose of having an example.

提交回复
热议问题