Join
the community
Sign-up
Ask a question »

Retrieve the result of command in a variable

May 2013


Retrieve the result of command in a variable







For specific reason, it is necessary to retrieve the result of a command (or back code) in variable to exploit the script later.

Below are different examples:

Syntax

var = $ (command)   

Note: Please note that the old method using reverse quotes ('command') is however forbidden and the examples presented here are better.


Examples
  • Recovery of standard out
    • stdout only
      • var=$(command)
    • stdout and stderr
      • var=$(command 2>&1)
  • Recovery back code ($?)
    • back code only
      • command
      • var=$?
    • Both
      • var=$ (command)
      • var=$?

See also

Knowledge communities.

Published by aakai1056 - Latest update by jak58
This document entitled « Retrieve the result of command in a variable » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.
Receive our newsletter

health.kioskea.net

Closing session- Quick log out
Unable to delete file: Argument list too long