Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 

To read the variable

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?


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}

Peter Godron
Honored Contributor

Re: To read the variable

how about :

echo $LV | wc -w

see "man wc"
Senthil Prabu.S_1
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.
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:

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:


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


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

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

Re: To read the variable

cool :)
Jesus is the King