[英]Suppress warning “Insecure world writable dir /some/dir/”
I've added the current directory to my $PATH ( PATH="$PATH":.
) to make it easier to run shell scripts in the current folder.我已将当前目录添加到我的 $PATH (
PATH="$PATH":.
) 中,以便更轻松地在当前文件夹中运行 shell 脚本。
Now I often see the following output before a shell command is executed:现在我经常在执行 shell 命令之前看到以下 output:
❯ cd Sites/project-a
❯ colorls
# /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229:
# warning: Insecure world writable dir /Users/philipp/Sites/project-a in PATH, mode 040777
#
# ... output of the colorls command ...
( colorls
is a ruby gem that I use instead of ls
, but I also use other gems in many scripts) (
colorls
是一个 ruby gem,我用它代替ls
,但我也在许多脚本中使用其他 gem)
I am aware of the meaning and the reason behind it, but I do not want a ruby script to dictate how I should configure my local system.我知道它背后的含义和原因,但我不希望 ruby 脚本指示我应该如何配置本地系统。
Is there a way to suppress the warning without changing the directory permissions?有没有办法在不更改目录权限的情况下抑制警告?
I could not find a way to globally disable the "Insecure world writable dir" warning.我找不到全局禁用“不安全的世界可写目录”警告的方法。
Another answer suggests replacing the ruby executable with a shell script or to recompile ruby with different options.另一个答案建议用 shell 脚本替换 ruby 可执行文件,或者用不同的选项重新编译 ruby。 Both options are difficult and could lead to other unexpected problems, in my opinion.
在我看来,这两种选择都很困难,并且可能导致其他意想不到的问题。
However, I found a way to disable the warning for individual scripts/gems:但是,我找到了一种禁用单个脚本/宝石警告的方法:
In my case, I use the gem colorls
to generate a nicer ls
output.就我而言,我使用 gem
colorls
生成更好的ls
output。 So far, this gem is the only one the frequently triggers the warning.到目前为止,这个 gem 是唯一一个经常触发警告的 gem。 I solved it, by adding the following alias to my
.zshrc
file (or .bash_profile
)我通过将以下别名添加到我的
.zshrc
文件(或.bash_profile
)来解决它
# Inside .zshrc
alias colorls='colorls --color=always 2>/dev/null'
The important part is the error redirection 2>/dev/null
.重要的部分是错误重定向
2>/dev/null
。
Good: This alias allows me to add custom parameters to the command, like colorls --report
好:这个别名允许我在命令中添加自定义参数,比如
colorls --report
Bad: This alias will mask any error or warning that the command produces.坏:此别名将掩盖命令产生的任何错误或警告。 I want to specifically remove the "Insecure world writable dir" warning.
我想专门删除“不安全的世界可写目录”警告。
# Inside .zshrc
alias colorls='colorls --color=always 2>&1 | grep "warning: Insecure world writable dir" -v'
Good: Instead of redirecting all errors to /dev/null
, my second attempt redirects all output to grep
, which strips out the individual warning message.好:我的第二次尝试不是将所有错误重定向到
/dev/null
,而是将所有 output 重定向到grep
,从而去除了单个警告消息。
Bad: That solution does not recognize any colorls
parameters;不好:该解决方案无法识别任何
colorls
参数; any parameter will be passed to grep
instead of colorls
...任何参数都将传递给
grep
而不是colorls
...
# Inside .zshrc
colorls() {
/usr/bin/colorls --color=always $@ 2>&1 | grep "warning: Insecure world writable dir" -v
}
This is the best solution: We replace the colorls
binary with a shell function.这是最好的解决方案:我们用 shell function 替换
colorls
二进制文件。 That shell function calls the binary. shell function 调用二进制文件。 The
$@
variable passes all parameters to the binary, while grep
removes the specific warning from the output. $@
变量将所有参数传递给二进制文件,而grep
删除了 output 中的特定警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.