Operating System - HP-UX
1833792 Members
2161 Online
110063 Solutions
New Discussion

Re: Scripting: howto preserve whitespace

 
SOLVED
Go to solution
Ralph Grothe
Honored Contributor

Scripting: howto preserve whitespace

Hi,

I seem to be blockheaded.
I cannot recall how to preserve whitespace with variable assignments in command substitutions when shell scripting.
In Perl this is no issue at all.
Please have a look at the attachment to see what I mean.

Regards
Ralph
Madness, thy name is system administration
7 REPLIES 7
Stefan Farrelly
Honored Contributor

Re: Scripting: howto preserve whitespace


use the IFS variable. Before you do cm=$(...
do; IFS=''
Then it echoes fine.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Leif Halvarsson_2
Honored Contributor

Re: Scripting: howto preserve whitespace

Hi
cm="/abd/def/gh iii jjj"
echo $cm
Steven Sim Kok Leong
Honored Contributor

Re: Scripting: howto preserve whitespace

Hi Ralph,

I would do this instead:

# /usr/sbin/cmviewcl -v -p depot > /tmp/cm.txt
# cm=/tmp/cm.txt
# cat $cm

Hope this helps. Regards.

Steven Sim Kok Leong
Stefan Farrelly
Honored Contributor
Solution

Re: Scripting: howto preserve whitespace


Ralph,

my earlier reply doesnt format well, its 2 single quotes (not a single double quote);
IFS='' (2 single quotes)
Im from Palmerston North, New Zealand, but somehow ended up in London...
Frank Slootweg
Honored Contributor

Re: Scripting: howto preserve whitespace

You just have to quote the variable when you use/display it, i.e. not

echo $cm

but

echo "$cm"

(I have not tried it with cmviewcl, but just with a cat(1) of a file containing your posted cmviewcl output. To be on the safe side, I did and "unexpand -a" on the file, so it did not only contain spaces, but also tabs.)
Ralph Grothe
Honored Contributor

Re: Scripting: howto preserve whitespace

Stefan,

yeah, that was it
of course, I forgot $IFS

In Perl its equivilant is the package global $/

Loks I've forgotten all about shell scripting :-(

Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Scripting: howto preserve whitespace

Frank,

your solution is preferable, because it's safer than tampering with IFS

Argh, how could I forgot the shells quoting mechanics?

Steven,

I want to avoid the creation of temporary files.
Madness, thy name is system administration