bash的循环跳过注释行(bash loop skip commented lines)

2019-07-31 17:22发布

我遍历文件中的行。 我只需要跳过以“#”开头的行。 我怎么做?

 #!/bin/sh 

 while read line; do
    if ["$line doesn't start with #"];then
     echo "line";
    fi
 done < /tmp/myfile

谢谢你的帮助!

Answer 1:

while read line; do
  case "$line" in \#*) continue ;; esac
  ...
done < /tmp/my/input

坦率地说,然而,它往往是更清晰的转向grep

grep -v '^#' < /tmp/myfile | { while read line; ...; done; }


文章来源: bash loop skip commented lines
标签: bash shell