简体   繁体   中英

Read lines from file in bash

For some strange reason, i'm unable to read line by line from a file in bash. I've always used the classic while read line; do echo $line; done < file.txt while read line; do echo $line; done < file.txt while read line; do echo $line; done < file.txt , but it suddenly stopped working.

Anybody knows if there was an update to bash recently that changed the sintaxis or similar?

Your question doesn't really provide enough detail to diagnose the problem. Fair enough, though: you don't know what the problem is so you don't know what's relevant. Here is a variant command which may address some of the more likely causes or would perhaps shed some light:

$ ( unset IFS; while builtin read line; do builtin echo xxx "$line" yyy; done < /etc/motd ) 
xxx  yyy
xxx The programs included with the Debian GNU/Linux system are free software;     yyy
xxx the exact distribution terms for each program are described in the yyy
xxx individual files in /usr/share/doc/*/copyright. yyy
xxx  yyy
xxx Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent yyy
xxx permitted by applicable law. yyy

What result do you get from the same command? The idea here is to check if the read or echo commands have been turned into aliases or shell functions. You could also check this with type echo and type read .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM