linux - "while read line"读取 C 文件时给出垃圾数据

标签 linux bash shell

<分区>

我想写一个小脚本来使用 shell 脚本解析 C 文件的所有注释,但我什至没有得到正确的读取 o/p,我得到的文件 o/p 与其他垃圾数据混合。

>/.1432804547.3007 /.1432804567.3007 /.1432804587.3007 /.1432804608.4021 /.1432804628.4021 /.1432804648.4021 /.1432804668.4021 /.1432804688.4021 /bin >/boot /dev /etc /home /lib /lib64 /lost+found /media /misc /mnt /net /opt /proc >/root /sbin /selinux /srv /sys /tmp /usr /var
>parsed_comments.tmp parse_func.sh file_update_time - update mtime and ctime time
>parsed_comments.tmp parse_func.sh @file: file accessed
>parsed_comments.tmp parse_func.sh
>parsed_comments.tmp parse_func.sh Update the mtime and ctime members of an inode and mark the inode
>parsed_comments.tmp parse_func.sh for writeback. Note that this function is meant exclusively for
>parsed_comments.tmp parse_func.sh usage in the file write path of filesystems, and filesystems may
>parsed_comments.tmp parse_func.sh choose to explicitly ignore update via this function with the
>parsed_comments.tmp parse_func.sh S_NOCMTIME inode flag, e.g. for network filesystem where these
>parsed_comments.tmp parse_func.sh timestamps are handled by the server.
>*/
>void file_update_time(struct file *file)

这是我正在做的..

   parse_comments() {
    local filename="$1"
    while read line; do
    echo $line | grep "*"
    done < "$filename"
    parse_comments "/root/rpmbuild/linux-2.6.32-431.17.1.el6.x86_64/fs/inode.c"

我已经尝试了所有解决方案(比如 - while read -r,while read -u 3 和其他)在 SO for while read problem 上告诉我没有一个解决方案对我有用。 我不知道 while 循环读取有什么问题请帮忙... 如果我将“awk”用于相同的工作,则效果很好。但是“awk”不符合我的目的。

最佳答案

问题已在 shellcheck.net 上解决.这是修改后的代码...

parse_comments() {
    local filename="$1"
    while read -r line; do
    echo "$line" | fgrep -e "*" 
    done < "$filename"
}
parse_comments "/root/rpmbuild/linux-2.6.32-431.17.1.el6.x86_64/fs/inode.c"

关于linux - "while read line"读取 C 文件时给出垃圾数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37634446/

相关文章:

python - 如何自动执行几个相互依赖的 Python 脚本

bash - 使用xargs ssh到多台主机,收到:Name or service not known

bash - 使用 awk 计算接口(interface)类型

linux - 如何在 .gitconfig 代理身份验证中转义特殊字符

java - maven java.lang.NoClassDefoundError Linux

linux - 使用 GRUB 自定义代码?

linux - Cassandra备份目录占用2GB

linux - 列出特定文件格式搜索后的文件数

bash - 为什么 `(( 0 ))`在.sh脚本中返回值为1?

bash - 如何在单个命令行中运行包含多个语句的 shell 脚本?