Support reading to stdout via builtin read -#4407
Conversation
|
Is it ok to use |
|
Is there a convention that Don't use Elsewhere in the shell we use |
Yes, but it is very rare. The I have to say I'm ambivalent about this change. In part because A bigger objection is that the current implementation allows mixing var names and the magic If this feature is added I would request that |
|
P.S., We really shouldn't be having this discussion in a change review. It belongs in an enhancement issue. |
|
Would it be better to allow |
Yes, that would be much better from a UI perspective and simpler to implement correctly. I'm still unconvinced it's useful enough to implement but if done that way I'd shrug my shoulders and give a weak thumbs up since it is marginally useful and doesn't overly complicate the code or introduce hard to document behavior. |
Fwiw, that's what I originally presumed |
That would have been the reasonable thing to do but instead it simply discarded the input. See issue #4220. |
|
Also think about how this feature interacts with |
|
The branch has been updated per the discussion above.
Additionally, the documentation has been updated to reflect the changes to |
Added an option to read to stdout via `read -`. While it may seem
useless at first blush, it lets you do things like include
mysql -p(read --silent) ...
Without needing to save to a local variable and then echo it back.
Kicks in when `-` is provided as the variable name to read to. This is
in keeping with the de facto syntax for reading/writing from/to
stdin/stdout instead of a file in, e.g., tar, cat, and other standard
unix utilities.
No longer using `-` to indicate reading to stdout. Use lack of arguments as stdout indicator. This prevents mixing of variables with stdout reading and makes it clear that stdout may not be mixed with delimiters or array mode.
|
Fixed unit tests for read invoked without parameters and will merge into master. Thanks, everyone. |
Added an option to read to stdout via
read -. While it may seemuseless at first blush, it lets you do things like include
Without needing to save to a local variable and then echo it back.
Kicks in when
-is provided as the variable name to read to. This isin keeping with the de facto syntax for reading/writing from/to
stdin/stdout instead of a file in, e.g., tar, cat, and other standard
unix utilities.
It doesn't make anything possible that wasn't previously doable with
(read temp_var; echo $temp_var)but it doesn't interfere with anything either and makes fish that much easier to use. Willing to reconsider if there is friction against including this in 3.0.