I am trying to execute the below command - but the output has some leading space introduced.
ls -lrt | wc -l
29
echo $SHELL
/bin/bash
When I run the same command on a different machine,the output is as expected.
ls -lrt | wc -l
183
echo $SHELL
/bin/bash
The leading spaces is causing my perl validation to fail
unless ( $phCountRet->{COUNT} =~ /^\d+$/ ){
...
}
I can opt to trim the leading white spaces and then do the validation,but it wont be a clean solution.
Any pointer as to what might be causing this will be a great help.
ls | wc -l | sed -e 's/^ *//'
doesn't seem any less clean thanls -lrt | wc -l
, but you could just do the equivalent ofperl -E 'say length glob "*"'
and not shell out to wc at all. – Linwc
with multiple file names, it aligns and right-justifies the numbers so they're more legible (at least some implementations do). The output is meant for to be human-readable than machine-readable. You just have to allow for variations in whitespace in the output. – Phenolic