To read the variable (244 Views)
Reply
Super Advisor
Piotr Kirklewski
Posts: 339
Registered: ‎01-12-2007
Message 1 of 7 (244 Views)
Accepted Solution

To read the variable

Hi there
I have variable set:

LV=`vgdisplay -v vg00|awk '{if (/LV Name/) {split($3,a,/\//);printf "%s ",a[4]}}
'`

echo $LV

The output looks like that:

lvol1 lvol2 lvol3 lvol4 lvol5 lvol6 lvol7 lvol8

I nead to read the variable contex, character by character so I can eventualy separate all names of lvols and count them.

Perhaps there is a simplier method to count the hov many separate words are there?

Regards

Jesus is the King
Honored Contributor
Oviwan
Posts: 692
Registered: ‎11-29-2005
Message 2 of 7 (244 Views)

Re: To read the variable

Hey

echo ${LV} | wc -w

for more info check man wc

to read each character do a for loop

for i in ${LV} ; do
echo ${i}
done

Regards
Honored Contributor
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 3 of 7 (244 Views)

Re: To read the variable

Hi,
how about :

echo $LV | wc -w

see "man wc"
Trusted Contributor
Senthil Prabu.S_1
Posts: 306
Registered: ‎10-10-2005
Message 4 of 7 (244 Views)

Re: To read the variable

Hi,
you can use wc command to do it with the switch -w.

so in your script, add this line;

echo $LV | wc -m

From wc man;
-m Counts characters

HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 7 (244 Views)

Re: To read the variable

Hi Piotr:

Based upon your questions, and without disrespect, you might find this shell overview helpful:

http://docs.hp.com/en/B2355-90046/B2355-90046.pdf

I would choose the Poxix shell since this is the HP-UX standard. It aligns closely to the Korn shell and Bash (in the Linux world) is another cousin.

A good site for shell scripts and techniques is also:

http://www.shelldorado.com/

Regards!

...JRF...
Honored Contributor
Ralph Grothe
Posts: 2,631
Registered: ‎04-09-2000
Message 6 of 7 (244 Views)

Re: To read the variable

Though the thread has been closed already,
but because no one mentioned the use of an array in this context.
You could slightly modify your assignment to

e.g.

# set -A LV $(vgdisplay -v vg00|awk '/LV Name/{split($3,a,/\//);print a[4]}')

# echo ${#LV[*]}
10
Madness, thy name is system administration
Super Advisor
Piotr Kirklewski
Posts: 339
Registered: ‎01-12-2007
Message 7 of 7 (244 Views)

Re: To read the variable

cool :)
Jesus is the King
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.