【Shell Check】Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

参考文档 https://www.shellcheck.net/wiki/SC2002

Problematic code:

### 这是我自己创建的配置文件
confFile=/opt/mongodb/config/config.conf
result=$(cat "$confFile" | grep port | sed 's/.*=\s*//g')

Correct code:

result=$(grep port "$confFile" | sed 's/.*=\s*//g')

grep 可以接受文件名作为参数,因此,我用 grep <keyword> <file> 代替 cat <file> | grep <keyword>

posted @ 2022-06-09 16:54  极客子羽  阅读(471)  评论(0)    收藏  举报