yori icon indicating copy to clipboard operation
yori copied to clipboard

yenv: accept variable from stdin

Open t214c opened this issue 2 years ago • 4 comments

Hi, Malcolm.

I looked a lot and I couldn't find a tool that accepts standard input and saves it to a variable. Something like this:

echo string | yenv var with the result: echo %var% > string

This is very useful because currently you have to make a full for loop to do this.

What do you think?

t214c avatar Jul 02 '23 17:07 t214c

I think I'm not understanding correctly :)

Isn't this set var=$(echo string) ?

That's really capturing stdout of echo into the variable.

Readline.exe exists to read from the console and write to standard output, although note it's a direct console read, not a standard input read. A standard input read seemed redundant here, since it would just be reading from input and writing to output, like type. But if you wanted to set a variable to a user supplied value, it could be:

set var=$(readline)

malxau avatar Jul 02 '23 17:07 malxau

set var=$(echo string)

Yeah, but this works only with Yori. I was talking about a tool that could work from any batch file.

It doesn't have to be yenv, it could be a new tool yset :)

t214c avatar Jul 02 '23 17:07 t214c

Okay, I think I understand. I pushed a4a01f070cd0338be4db1223a52ebf8a7faae230 for this, although am still not happy; I think it should also support both a variable and value from stdin, but having done that, it could have a list of variables and values, and...

malxau avatar Aug 19 '23 20:08 malxau

Thanks a lot!

although am still not happy

Like I said, it doesn't have to be yenv at all. I just wanted a simple tool to abstract away the for loop (and character escaping) required to set a command output to a variable by piping. Advanced or multiple variable support is cherry on the top.

t214c avatar Aug 24 '23 16:08 t214c