简体   繁体   English

emacs flycheck(bash with shellcheck)在使用可选字符时抛出错误

[英]emacs flycheck (bash with shellcheck) throws error when using optional characters

I was trying to improve a function definition using flycheck (shellcheck).我试图使用 flycheck (shellcheck) 改进函数定义。 The commented line on the code below is what I tried to improve.下面代码的注释行是我试图改进的。 The code works but I get the error message syntax error near unexpected token ('`该代码有效,但我收到错误消息syntax error near unexpected token ('`

my_loop() {
# for ifastq in $(ls $1 | grep -v txt)
for ifastq in $1/*.f?(ast)q?(.gz)
do
echo "$ifastq"
done
}

Is the code above more fragile than the one using the commented line?上面的代码是否比使用注释行的代码更脆弱? Should I also include shopt -s extglob in the function definition or at the top of the script?我还应该在函数定义中或脚本顶部包含shopt -s extglob吗?

Thanks谢谢

BTW: the code is supposed to capture files with.fastq.fq fq.gz or.fastq.gz extensions顺便说一句:代码应该捕获扩展名为.fastq.fq fq.gz 或.fastq.gz 的文件

Is the code above more fragile than the one using the commented line?上面的代码是否比使用注释行的代码更脆弱?

No, the opposite.不,恰恰相反。 It's generally a bad idea to process the output of ls .处理ls的输出通常不是一个好主意。 If any of the filenames contains whitespace, it will be split into multiple words when you use $(ls...) .如果任何文件名包含空格,当您使用$(ls...)时,它将被分成多个单词。

You do need to enable extglob , since it's not enabled by default.您确实需要启用extglob ,因为默认情况下未启用它。

Extended globbing is a bash extension, Flycheck might not recognize it. Extended globbing 是bash扩展,Flycheck 可能无法识别它。 Emacs SE would be a better place to ask questions specific to this Emacs extension. Emacs SE将是一个更好的地方来询问特定于这个 Emacs 扩展的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM