I found this in some code I was working on. It was designed to work around a requirement to read a keyfile from disk. In production the contents of the keyfile were in an environment variable.
Old code:
key = File.read('path/to/key.pem')
New code:
key = File.read('| echo $KEY_VARIABLE')
How does this work?
From the IO docs:
A string starting with “|” indicates a subprocess. The remainder of the string following the “|” is invoked as a process with appropriate input/output channels connected to it.
The "channels connected" bit means that the output of the process will become the input for read
. So in this example the result from the echo
of the environment variable can be read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With