get leading spaces into EnvVar

Hi!

this all in ksh!!!

think of something like
...|cut -f8- -d";"
now I want something like
...|cut -f8- -d";"|read XYZ
echo "$XYZ"

The problem is, that leading spaces are ignored by "read"!
What read does wrong, export does right!

export XYZ="     123"
echo "$XYZ"
     123

So I want to pipe into export!
How can I solve this??

Thanks
Witty

LVL 1
wittyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mliberiConnect With a Mentor Commented:
read uses IFS environment variable to tokenize input lines. So just set IFS to the empty string before reading.

example:
IFSsave=$IFS    # save IFS value
.... | read XYZ
IFS=$IFSsave    # restore saved value

You may also want to ignore special sequences, such as \n \t \r etc., using '-r' (raw read) option.

enjoy.
0
 
tfewsterCommented:
How about XYZ=`...|cut -f8- -d";"` ?
0
 
mliberiCommented:
you could also use the following syntax instead of using 'read'

XYZ="$(...|cut ...)"
0
 
wittyAuthor Commented:
mliberi,

cool, this was exactly, what I needed!!!

Thank you VERY much
Michael
0
All Courses

From novice to tech pro — start learning today.