BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

To read the variable

Go to Solution
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?


Jesus is the King
Honored Contributor

Re: To read the variable


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}

Honored Contributor

Re: To read the variable

how about :

echo $LV | wc -w

see "man wc"
Trusted Contributor

Re: To read the variable

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

One man's "magic" is another man's engineering. "Supernatural" is a null word.
Acclaimed Contributor

Re: To read the variable

Hi Piotr:

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

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:


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


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

# echo ${#LV[*]}
Madness, thy name is system administration
Super Advisor

Re: To read the variable

cool :)
Jesus is the King