已关闭。此问题需要details or clarity。它目前不接受回答。
**希望改进此问题?**通过editing this post添加详细信息并阐明问题。
三年前就关了。
Improve this question的
如何删除shellcheck的警告“SC2154”当linting shell脚本?
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
echo "proxy=$http_proxy" | sudo tee -a /etc/test.txt
字符串
警告为“SC2154:http_proxy被引用但未分配。”
编辑:我想使用sudo将环境变量“http_proxy”写入test.txt文件。
2条答案
按热度按时间dm7nw8vv1#
一般来说,更好的解决方案是坚持约定并在ALL_CAPS中命名 your 环境变量。但是,在本例中,我理解
http_proxy
不是 * 您的 * 环境变量,而是由curl
、wget
等程序指定的,因此您不能简单地重命名它。您可以suppress any warning与评论:
字符串
这将忽略从该行开始的有关
http_proxy
的错误。后续的$http_proxy
也不会给予错误,但其他变量会。要在一个中心位置禁用多个变量的警告,请在脚本开头的代码段下面放置。警告:Shellcheck directives before the first command in your script will apply to the whole script。作为一种解决方法,将虚拟命令(例如
true
)。型
sh7euo9m2#
如果
http_proxy
为null或未设置,则可以显式地将其扩展为nothing,以抑制警告:字符串