标签: shellcheck

即使给定了开始搜索的路径,shellcheck 也会警告 find 输出上的循环

Ubuntu 16.04

#!/bin/bash

site="hello"
wDir="/home/websites/${site}/httpdocs/"

for file in $(find "${wDir}" -name "*.css")
do
   echo "$file";
done
exit 0;
Run Code Online (Sandbox Code Playgroud)

即使我定义了开始目录,shellcheck 也会警告我,但脚本工作得很好。

root@me /scripts/ # shellcheck test.sh

In test.sh line 6:
for file in $(find "${wDir}" -name "*.css")
            ^-- SC2044: For loops over find output are fragile. Use find -exec or a while read loop.
Run Code Online (Sandbox Code Playgroud)

bash find shellcheck

3
推荐指数
2
解决办法
1260
查看次数

VS Code 编辑器 | 如何为 ShellCheck 包含 -x 开关?

问题描述及复现

在终端运行中:

shellcheck -x my_script
Run Code Online (Sandbox Code Playgroud)

哪里my_script来源另一个(部分)脚本。

-x开关没有错误,但如果我没有-x运行它:

shellcheck my_script
Run Code Online (Sandbox Code Playgroud)

我收到这样的通知:

. ./functions/my_function

  ^-- SC1091: Not following: ... was not specified as input (see shellcheck -x).
Run Code Online (Sandbox Code Playgroud)

GitHub 上的 SC1091


我的外壳检查

我正在使用位于以下位置的自编译 ShellCheck:

~/.cabal/bin/shellcheck
Run Code Online (Sandbox Code Playgroud)

目标

我正在使用Visual Studio Code GUI 文本编辑器。有没有办法强制-x开关在某处或其他解决方案?

scripting shellcheck visual-studio-code

1
推荐指数
1
解决办法
723
查看次数

Bash - 使用 glob 打印反向文件列表

有没有办法通过 glob 反转文件列表?

所以我会得到与以下相同的结果:

ls -r *
Run Code Online (Sandbox Code Playgroud)

我在 shell 脚本中使用它并shellcheck不断抱怨:

^--------^ SC2045:迭代 ls 输出是脆弱的。使用球体。

ls bash wildcards shellcheck

1
推荐指数
1
解决办法
835
查看次数

如何以符合 posix 的方式通过提示获取用户输入到变量中

read -r -p "put an option: " option
echo $option
Run Code Online (Sandbox Code Playgroud)

这有效,但 shellcheck 给了我:

In POSIX sh, read -p is undefined.
Run Code Online (Sandbox Code Playgroud)

如何以符合 posix 的方式通过提示获取用户输入到变量中?

shell-script posix read shellcheck

1
推荐指数
1
解决办法
179
查看次数

“确保不要在同一个管道中读写同一个文件”

shellcheck 报告:

echo -e "blah/blah\n$(cat "$tmpdir"/"$filename".jpdf)" > "$tmpdir"/"$filename".jpdf
                          ^-- SC2094: Make sure not to read and write the same file in the same pipeline.
                                                         ^-- SC2094: Make sure not to read and write the same file in the same pipeline.
Run Code Online (Sandbox Code Playgroud)

blah/blah该命令的目的是在文件的开头插入一行"$tmpdir"/"$filename".jpdf

“确保不在同一管道中读取和写入同一文件”是什么意思?

我该怎么办呢?

谢谢。

bash shellcheck

0
推荐指数
1
解决办法
2955
查看次数