-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oil should have a slurp builtin #711
Comments
So like: while read -r line; do
myvar+=$line$'\n'
done <myfile.txt
[[ -n $line ]] && myvar+=$line But shorter and probably much faster as well, of course. |
Another solution with mapfile myvar < myfile.txt
IFS= eval 'myvar="${myvar[*]}"' If one can assume that there is no mapfile -d '' myvar < myfile.txt Or, with IFS= TMOUT= read -r -d '' myvar < myfile.txt || [[ $myvar ]] |
Ah OK And Oil supports NUL bytes, so that would work with either So I guess
|
It might be easier to simply add another option or two to "read"; read is already (essentially) reserved. E.g., "-R" (raw) option would ignore IFS & not re-interpret anything, and simply load stdin's contents into the named variable (up to the byte length limits if given). |
Yeah that is possible -- it's a matter of style. If that were the case I'd want to implement Oil currently has:
So it could be I added that principle here: https://github.com/oilshell/oil/wiki/Language-Design-Principles e.g. I believe Thanks for the feedback. |
It is possibly safer to create But shells already stomp all over other commands like |
OK we now have
I have been getting feedback that it's better not to stomp on the "first word" namespace, so these are indeed long flags, rather than Feedback is welcome! |
Problems:
1
in some contexts. Because no delimiter is read.$(cat myfile.txt)
omits the newline.So
slurp
can be used as follows:related:
getline
, becauseread -r
isn't the default.The text was updated successfully, but these errors were encountered: