Operating System - HP-UX
1834137 Members
2312 Online
110064 Solutions
New Discussion

Re: Simple script question...

 
SOLVED
Go to solution
Gene Laoyan
Super Advisor

Simple script question...

I assign my variable via...
mylog=`hpvmstatus -P scottk_1 | grep scsi`

A typical output from "hpvmstatus -P scottk_1 | grep scsi" gives me the following...
disk scsi 0 0 0 0 0 disk /dev/rdsk/c6t10d0
dvd scsi 0 0 0 1 0 file /tmp/Win2003Server_Itanium-withSP1-AX2EIVOL_EN.iso
disk scsi 0 0 0 2 0 disk /dev/rdsk/c6t10d1

Why does it look like this...
disk scsi 0 0 0 0 0 disk /dev/rdsk/c6t10d0 dvd scsi 0 0 0 1 0 file /tmp/Win2003Server_Itanium-withSP1-AX2EIVOL_EN.iso disk scsi 0 0 0 2
0 disk /dev/rdsk/c6t10d1
when I assign the output to a variable?

I want to keep the formatting and append it after I make a change to the VM's configuration of the disks.

How do I do that?
6 REPLIES 6
Dennis Handly
Acclaimed Contributor
Solution

Re: Simple script question...

If you want to keep the formatting, you must put it in a file. You might be able to use sed to change a newline to some other character then change it back just before you print it.
Gene Laoyan
Super Advisor

Re: Simple script question...

Damn....
I was afraid you'd say that......lol
I guess I'll log to a file instead of build the log into a variable then write it to a text file.

Thanks for your help.

Hemmetter
Esteemed Contributor

Re: Simple script question...

Hi Gene

Try setting IFS to newline before e.g. echoing it:
# mylog=`hpvmstatus -P scottk_1 | grep scsi`
# IFS=\
+
# echo $mylog

rgds
HGH
Dennis Handly
Acclaimed Contributor

Re: Simple script question...

Hmm, I can't duplicate your problem. The variable in my case has the embedded newlines and everything seems to work fine.
Peter Nikitka
Honored Contributor

Re: Simple script question...

Hi,

the assignment to the variable does NOT change the formatting! It is the way you do your output.
Formatting preserved:
print "$mylog"

Formatting ignored:
print $mylog

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Gene Laoyan
Super Advisor

Re: Simple script question...

Peter you're a genius!
Points awarded.
Thanks