count the number of items in a shell variable

Viewed 4336

I have a shell variable sampleDir:

sampleDir=/home/sample*
echo $sampleDir

will give:

/home/sample_001 /home/sample_002 /home/sample_003

(note there are sub-directories under the sample_*** ones)

If I would like to count how much of these items are in this $sampleDir variable, what would be a best way please? (Expect to return 3)

3 Answers
Related