Linux /bin/sh check if string contains X

前端 未结 3 949
终归单人心
终归单人心 2021-01-05 01:36

In a shell script, how can I find out if a string is contained within another string. In bash, I would just use =~, but I am not sure how I can do the same in /bin/sh. Is i

3条回答
  •  悲&欢浪女
    2021-01-05 01:37

    You can try lookup 'his' in 'This is a test'

    TEST="This is a test"
    if [ "$TEST" != "${TEST/his/}" ]
    then
    echo "$TEST"
    fi
    

提交回复
热议问题