-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Ability to read multiline content into variable #1147
Comments
I wonder if this could be a flag to
Perhaps? |
We definitely don't want something like bash's syntax! As you have noted it is possible to use a read loop ( Some possibilities:
Of course, #159 may trip you up... |
I was worried that read would show me a prompt after the last line from pipe, but in fact it just passes it by. I ended with:
(
I didn't know about #159, probably this issue could be closed as a duplicate of #159. |
Ehh, the trailing line was from
|
I'm really missing something like Bash's
And the result would be an array with each line from
Maybe I'm missing something, but I can't find any way to emulate this in Fish, so this is a showstopper. :( |
@alphapapa Perhaps I'm misunderstanding, but this should just work?
|
I'm sorry, I guess it had been a while since I tried using Fish to write a script, and I got confused. I think what confused me was that doing something like this:
...removes all of the line breaks, making it appear that it's a single-element variable instead of an array with one line per element. Is that intended behavior? Thanks for your patient answer when I probably deserved a "RTM". :) |
@alphapapa: See #159 - and actually this issue as well. |
As the topic was already dragged out from the shadow I have a related question. Proposed workaround to put a multiline content from a pipe to a variable:
adds unnecessary I cannot use |
If you can put the pipe inside a command substitution, you can disable IFS and use this to your advantage: > set IFS ''; set var (printf 'foo\nbar\n')
> echo $var
foo
bar
> count $var
1 |
Looking back, I don't think there's anything else to do here. You can use read in a pipeline with the So I'm going to close this for now! If you think I've missed something, speak up. |
For others that run across this, here is a concrete example of what @zanchey is talking about:
|
You can even do |
Leaving another example here that is very similar to #1147 (comment) but may not be obvious to others. It cats out the file into a list/array.
e.g.
|
It would be useful to be able to read multiline input into variable for further usages. For example:
cat myfile | myscript
where in myscript a content of the file is read and passed (for example) to
a clipboard.
In Bash a weird construction like "input="$(< /dev/stdin)" can be used.
The text was updated successfully, but these errors were encountered: