Recover result of command in a variable

Last update on August 7, 2009 02:15 PM by jak58
Published by aakai1056

Recover result of command in a variable









For specific reason, it is necessary to recover 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=$?
Best answers for « Recover result of command in a variable » in :
Environment variables Show Environment variables An environment variable is a dynamic value loaded into the memory that can be used by several processes operating simultaneously. On most operating systems, the location of some libraries or of the main system executables may...
Replacing Variables in Bash/shell Show Replacing Variables in Bash/shell Intro: Expression:Defininition Intro: First of all make sure that you the variable is defined before replacing it, or in other cases determine that it is not empty, and to initialize with a default...
[Oracle] Recover lost passwords Show [Oracle] Recover lost passwords To recover a password in Oracle, simply connect under command line mode on the server: #sqlplus /nolog SQL>conn / as sysdba SQL>alter user Username identified by password;
Command prompts for Windows ShowCommand prompts for Windows Some of these command below can cause harmful an undesirable functions, leading to the formatting of your hard disk and data loss, while others will not run under Windows XP. As for Windows Vista the Run Tab is not...
How to change or recover your Windows Live Messenger password ShowHow to change or recover your Windows Live Messenger password 1.Changing your password (Windows Live Messenger) 2. Password Recovery Secret question Send password reset instructions to your alternative email address Download MSN Messenger...
Command to detect your IP address! ShowCommand to detect your IP address! Command for Windows 2000 / XP / Vista Command for Windows 95/98 Command for Linux IP address (Internet Protocol) is a numerical identification to detect your computer on a network. It is used to...
Network tests and diagnostics ShowTesting the IP configuration Before doing anything else, you are advised to check the computer's IP configuration. Windows systems offer a command-line tool, called ipconfig, that lets you find out your computer's IP configuration. The output of...
Book disk ShowSystem disk A system disk, also sometimes called a boot disk, is a disk that will allow you to start a computer when the operating system no longer responds, as the result of a virus for example. This disk contains special information that makes it...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...