As POSIX defined, the output of wc
shall contain an entry for each input file of the form:
"%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
But the output file format pseudo printf()
string differs from the System V version of wc
:
"%7d%7d%7d %s\n"
POSIX didn't require leading spaces to be added, so it's free for implementation to do what it want. There are different implementations of wc
, at least with OSX and wc
from heirloom tools chest, it added leading spaces to output.
$ /usr/5bin/wc -l /tmp/file
3 /tmp/file
GNU wc also add leading spaces when reading from standard in and without any options:
$ cat file | wc
5 5 65
To remove all leading spaces, in POSIX shell:
set -f
set -- $nl
nl=$1
set +f
Note that this approach assume that variable only contain leading or trailing spaces, no spaces in the middle, like a b.
nl=100
; 2) try different delimiter, not-
; 3) put double quotes around expressionecho "1-$nl"
; 4) useprintf
instead ofecho
– jimmij May 27 '15 at 16:03echo $nl
asecho "$nl"
. – Janis May 27 '15 at 16:03