How can you use pure unset shell builtin? Can you write shell scripts that are immune to tampering?

前端 未结 3 1685
时光取名叫无心
时光取名叫无心 2021-01-01 07:32

I mean I want to use unset that is not a shell function itself. If I could do that, I could make sure that command is pure by running



        
3条回答
  •  一生所求
    2021-01-01 08:25

    This is what I know what can be done...

    #!/bin/bash --posix
    
    # if e.g. BASH_FUNC_unset() env variable is set, script execution cannot
    # get this far (provided that it is run as is, not as `bash script ...`)
    
    unset -f builtin command declare ...
    
    saved_IFS=$IFS; readonly saved_IFS
    # remove all functions (shell builtin declare executed in subshell)
    IFS=$'\n'; for f in `declare -Fx`; do unset -f ${f##* }; done; IFS=$saved_IFS
    

提交回复
热议问题