Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

To read the variable

SOLVED
Go to solution
Piotr Kirklewski
Super Advisor

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
6 REPLIES
Oviwan
Honored Contributor
Solution

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
Peter Godron
Honored Contributor

Re: To read the variable

Hi,
how about :

echo $LV | wc -w

see "man wc"
Senthil Prabu.S_1
Trusted Contributor

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.
James R. Ferguson
Acclaimed Contributor

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...
Ralph Grothe
Honored Contributor

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
Highlighted
Piotr Kirklewski
Super Advisor

Re: To read the variable

cool :)
Jesus is the King