在bash调试运行期间隐藏信息 [英] Hide information during bash debug run
问题描述
我们在shell脚本中调试了run(bash -x ./my_script.sh),以了解/显示它的作用.但是这样做可能会显示一些我不希望看到的敏感信息,例如密码.我的脚本从安全库中提取密码,并在需要时将其作为变量传递给脚本.
We do debug run(bash -x ./my_script.sh) in a shell script to understand/show what it is doing. But in doing so it might show some sensitive information that I dont want to be visible, such as passwords. My script extracts the password from a secure vault and passes it as a variable within the script when required.
所以,我想了解一下是否有一种方法可以在Shell脚本的调试运行期间哈希/隐藏此类敏感信息?(大概没办法吗?)
So, I want to understand if there is a way to hash/hide such sensitive information during a debug run of shell script? (Probably No way?)
推荐答案
对具有敏感信息的部件禁用调试,然后重新启用它.
Disable debugging for the part with sensitive information and re-enable it afterwards.
if [[ $- =~ x ]]; then debug=1; set +x; fi
# your code with sensitive information
[[ $debug == 1 ]] && set -x
这篇关于在bash调试运行期间隐藏信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!