Operating System - HP-UX
1748052 Members
4705 Online
108758 Solutions
New Discussion юеВ

Re: Shell scripting - Storing command output in a variable

 
SOLVED
Go to solution
vinna
New Member

Shell scripting - Storing command output in a variable

I am making a tool with shell script to report utilization. In the script, i am storing some command output in a variable. At the end of the script, i am printing the o/p stored in the variable. But it prints the varaible not exactly as the output of the actual command. In other words, it prints everything in single line one after after other.

Example:

Command output:
$ lspv | grep active | grep 15
hdiskpower15 0000792a05830e15 Ora0600 active
hdiskpower115 0000792a9c882ece Ora0600 active

$ opt_cmd=`lspv | grep active | grep 15`

$ echo $opt_cmd
hdiskpower15 0000792a05830e15 Ora0600 active hdiskpower115 0000792a9c882ece Ora0600 active

Can someone tell me is there any way i can store the output to a varibale exactly same as the command output.
5 REPLIES 5
Dennis Handly
Acclaimed Contributor

Re: Shell scripting - Storing command output in a variable

Have you tried: echo "$opt_cmd"?

Otherwise you'll need to save the output in a file:
lspv | grep active | grep 15 > output
opt_cmd=$(< output)
vinna
New Member

Re: Shell scripting - Storing command output in a variable

I tried with "$opt_cmd". It works. Thanks
Dennis Handly
Acclaimed Contributor
Solution

Re: Shell scripting - Storing command output in a variable

If you are happy with the answers, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
James R. Ferguson
Acclaimed Contributor

Re: Shell scripting - Storing command output in a variable

Hi:

You have to love these postings from AIX environments (not that it matters for this question) :-) I guess is shows how valuable a place the ITRC can be.

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: Shell scripting - Storing command output in a variable

> [...] I guess is shows how valuable a place
> the ITRC can be.

Or how thoroughly lost and confused its users
can be.