I have a external program (kind of an authentication token generator) that outputs two lines, two parts of my authentication.
$ get-auth
SomeAuthString1
SomeAuthString2
Then, I want to export these strings into an environment variable, say, AUTH
and PIN
.
I tried several things in bash, but nothing works.
For example, I can do:
get-auth | read -d$'\4' AUTH PIN
but it fails. AUTH and PIN remain unset. If I do
get-auth | paste -d\ -s | read AUTH PIN
it also fails. The only way I can get the data is by doing
get-auth | { read AUTH; read PIN; }
but obviously only in the subshell. Exporting from that has no result
A bit of research, and I found this answer that might mean that I can't do that (reading a variable from something piped into a read). But I might be wrong. I also found that if I open a subshell with {
before the read, the values are available in the subshell until I finish it with }
.
Is there any way I can set environment variables from the two-line output? I obviously don't want to save that to a file, and I don't want to set up a FIFO just for that. Are those the only ways of getting that done?