Issue
For a command like:
/command -in input_filename -of output_filename
is it possible to use a variable
instead of output_filename
I have tried redirections but that didn't work
Edit:
After reading comments and answers I feel perhaps the question is confusing. Executable expects filename for its output. However, I want to save that output in a variable.
Solution
You can not specify a variable as an output file and then have it populated.
Instead, have the program write to stdout and capture it. How you do this depends on the command. Since you don't specify, here is an example with curl
:
# Many programs automatically write to stdout when a file is not specified
myvar=$(curl http://stackoverflow.com)
# Many programs accept - to mean stdout for output files
myvar=$(curl -o - http://stackoverflow.com)
# Otherwise, you can often specify /dev/stdout
myvar=$(curl -o /dev/stdout http://stackoverflow.com)
If this isn't possible because the command doesn't have clean output, you may be forced to write it to a temporary file and read it back.
Answered By - that other guy Answer Checked By - Marie Seifert (WPSolving Admin)