There is no read applet comming with busy box.
Is there any way to read a txt file line by line using busybox?
What I have now is
while read line do echo $line done < "$InputFile"
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
read is a shell builtin (it couldn't set a shell variable if it were not).
So, if your busybox
sh is based on
while IFS= read -r line <&3; do printf '%s\n' "$line" done 3< "$InputFile"
Like in any POSIX shell. But like with any shell, using
while read loops to process text is generally bad shell scripting practice.
Above, you need:
IFS=otherwise leading and trailing unescaped spaces and tabs are stripped from the lines
-r, otherwise backslashes are treated as an escape character and removed (unless escaped)
echowhich wouldn't work for lines that are for instance
$line) otherwise the content of the line is split on spaces and tabs, and globbing patterns expanded.
3< ..., if you need access to the original stdin within the loop.
If the file contains characters after the last line and you want to display them, you can add after the loop:
[ -z "$line" ] || printf %s "$line"
Note that that loop cannot handle binary data (the