How can I grep complex strings in variables?

后端 未结 4 1538
情歌与酒
情歌与酒 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:46

    grep is for files or stdin. If you want to use a variable as stdin then you need to use bash's herestring notation:

    if grep -q "$shrt_str" <<< "$long_str" ; then
    

提交回复
热议问题