malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.24k stars 31 forks source link

yenv: accept variable from stdin #114

Open t214c opened 1 year ago

t214c commented 1 year ago

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?

malxau commented 1 year ago

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)

t214c commented 1 year ago

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 :)

malxau commented 1 year ago

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...

t214c commented 1 year ago

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.