Make shopt change local to function

前端 未结 4 1875
渐次进展
渐次进展 2021-01-01 10:03

I\'m trying to write a bash function that uses nocasematch without changing the callers setting of the option. The function definition is:

is_he         


        
4条回答
  •  Happy的楠姐
    2021-01-01 10:56

    The function body can be any compound command, not just a group command ( {} ). Use a sub-shell:

    is_hello_world() (
      shopt -s nocasematch
      [[ "$1" =~ "hello world" ]] 
    )
    

提交回复
热议问题