我正在遍历文件中的行。我只需要跳过以“#”开头的行。 我该怎么做?
#!/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
通常会更清楚:
grep -v '^#' < /tmp/myfile | { while read line; ...; done; }
关于bash 循环跳过注释行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488556/