I have a variable which is having the value like below,
$ echo ${p}
8 15 22 30
$
My requirement is that the variable should return true when it contains only one number like below,
$ echo ${p}
15
$
Otherwise, it should return false if it contains more than one number.
I tried to find out the if loop operator which helps in this, but could not find anything.
Could anyone help me in this please?
If you'd like a reasonably bullet-proof solution, specify the exact forms that the numeric representation is allowed to assume.
Because we have no context, it's possible that the best solution lies in an earlier step, when or before the variable is assigned.
In my opinion, Scrutinizer's first suggestion is best. It doesn't require any external utilities, so it's efficient. It is also trivially extensible, for handling multiple representations.
I wouldn't recommend the following for production use. It's more an exercise in utility abuse than anything else ;):