Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In bash, how to store stdin and stdout file handle in variable?

I have the following bash script:

STDIN='&0'
if some-condition; then
  STDIN=some-filename
fi

run-command <${STDIN}

But that errors with &0: No such file or directory.

Similarly for STDOUT.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve tried using eval but haven’t gotten that to work, either.

What needs to be done to get this to work?

>Solution :

STDIN=’/dev/stdin’ # Default to stdin

if some-condition; then

STDIN=’some-filename’

fi

Similarly, for STDOUT

STDOUT=’/dev/stdout’ # Default to stdout

if some-other-condition; then

STDOUT=’some-other-filename’

fi

run-command <"$STDIN" >"$STDOUT"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading