bash循环跳过注释行 [英] bash loop skip commented lines

查看:56
本文介绍了bash循环跳过注释行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历文件中的行.我只需要跳过以#"开头的行.我该怎么办?

I'm looping over lines in a file. I just need to skip lines that start with "#". How do I do that?

 #!/bin/sh 

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

感谢您的帮助!

推荐答案

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

但是,坦率地说,通常更容易找到 grep :

Frankly, however, it is often clearer to turn to grep:

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

这篇关于bash循环跳过注释行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆