简体   繁体   English

禁止警告“不安全的世界可写目录/some/dir/”

[英]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 )来解决它

Solution 1解决方案 1

# 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.我想专门删除“不安全的世界可写目录”警告。

Solution 2解决方案 2

# 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 ...

Solution 3 (best)解决方案 3(最佳)

# 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.

相关问题 警告:PATH模式040777下不安全的世界可写目录/ usr - warning: Insecure world writable dir /usr in PATH, mode 040777 如何在PATH中解决不安全的世界可写dir / usr,在Ruby上模式040777警告? - How to solve Insecure world writable dir /usr in PATH,mode 040777 warning on Ruby? 在PATH中获取警告“不安全世界可写dir / home / chance”,模式040777用于rails和gem - Getting the warning “Insecure world writable dir /home/chance ” in PATH, mode 040777 for rails and gem 警告:不安全的世界可写目录…/osx/bin 在 PATH,模式 040777 与 Homebrew - warning: Insecure world writable dir …/osx/bin in PATH, mode 040777 with Homebrew 运行ruby脚本时出现错误的“ PATH中不安全的世界可写dir foo” - Erroneous “Insecure world writable dir foo in PATH” when running ruby script 耙任务提示不安全的可写目录 - Rake tasks prompt insecure writable dir 运行“rails s”后如何修复“路径中不安全的世界可写目录/mnt/c,模式040777”错误 - How to fix "Insecure world writable dir /mnt/c in PATH, mode 040777" error after running "rails s" 运行 Ruby 命令时,PATH 中不安全的世界可写目录/用户/用户名,模式 040777 - Insecure world writable dir /Users/username in PATH, mode 040777 when running Ruby commands 尝试安装 Ruby 1.9.3-p547 退出时出现警告:无法识别的选项:--with-libyaml-dir、--with-readline-dir - Trying to install Ruby 1.9.3-p547 exits with WARNING: unrecognized options: --with-libyaml-dir, --with-readline-dir Ruby-线程和Dir []数组 - Ruby - Threads and Dir[] arrays
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM