Linux / UNIX Tech Support Forum
This is a discussion on Shell store or return output of a command in a variable within the Shell scripting forums, part of the Development/Scripting category; I can store command output using $(cmd) or `cmd`. But how do get stdout+stderr in a variable? Also, some script ...
|
Register free or login to your existing account and remove all advertisements. |
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
| Sponsored Links | ||
|
|
|
||||
|
Quote:
Code:
cmd1 ret=$? return $ret Code:
tar -zcvf /dev/st0 /home && echo "Backup done" || echo "Backup Failed" Quote:
Code:
output=$(cmd1 2>&1) Code:
output=`command-name 2>&1`
__________________
Vivek Gite Linux Evangelist |
|
||||
|
Quote:
Code:
var=$(cmd1 2>&1) Code:
var=$(cmd1 2>&1 >/dev/null)
__________________
Vivek Gite Linux Evangelist |
| The Following User Says Thank You to nixcraft For This Useful Post: | ||
chimu (07-05-2009)
| ||
![]() |
| Tags |
| bash , csh , exit status , ksh , return value , scripting , shell store output , var=$(cmd1 2>&1 >/dev/null) , var=$(cmd1 2>&1) |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parse XML file and store data in array in shell scripting | Nishanthhampali | Shell scripting | 6 | 12-15-2009 08:37 PM |
| set shell variable uses which file in RHEL5.1?? | knvpavan | Shell scripting | 2 | 05-19-2009 06:39 AM |
| save command and command output | savook | CentOS / RHEL / Fedora | 1 | 05-08-2009 06:33 PM |
| How to Redirect OutPut of Shell Command to a text file | Hadi | Shell scripting | 1 | 04-29-2009 08:27 PM |
| Shell Creates a variable that stores the results of the command | blingbling | Shell scripting | 1 | 03-16-2009 08:41 PM |