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 ...
|
|||||||
| 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 (05-07-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 | 15-12-2009 07:37 PM |
| set shell variable uses which file in RHEL5.1?? | knvpavan | Shell scripting | 2 | 19-05-2009 05:39 AM |
| save command and command output | savook | CentOS / RHEL / Fedora | 1 | 08-05-2009 05:33 PM |
| How to Redirect OutPut of Shell Command to a text file | Hadi | Shell scripting | 1 | 29-04-2009 07:27 PM |
| Shell Creates a variable that stores the results of the command | blingbling | Shell scripting | 1 | 16-03-2009 07:41 PM |