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) 在终端运行中:
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)
我正在使用位于以下位置的自编译 ShellCheck:
~/.cabal/bin/shellcheck
Run Code Online (Sandbox Code Playgroud)
我正在使用Visual Studio Code GUI 文本编辑器。有没有办法强制-x开关在某处或其他解决方案?
有没有办法通过 glob 反转文件列表?
所以我会得到与以下相同的结果:
ls -r *
Run Code Online (Sandbox Code Playgroud)
我在 shell 脚本中使用它并shellcheck不断抱怨:
^--------^ SC2045:迭代 ls 输出是脆弱的。使用球体。
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 的方式通过提示获取用户输入到变量中?
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。
“确保不在同一管道中读取和写入同一文件”是什么意思?
我该怎么办呢?
谢谢。
shellcheck ×5
bash ×3
find ×1
ls ×1
posix ×1
read ×1
scripting ×1
shell-script ×1
wildcards ×1