From: Brian Gernhardt <hidden> Date: 2016-06-15 22:52:38
It's time for my periodic complaint: People assuming `wc -l` outputs just a number. wc on OS X (and perhaps other BSD-like systems) always aligns the output in columns, even with the -l flag. Generally this results in a quick patch from me to remove some unneeded quotes. However, this time it's used in a more complex manner:
echo "SHA " \
"($(git ls-files|wc -l) entries, 0 subtrees)" >expect &&
cmp_cache_tree expect
This results in errors like:
I was able to fix this by adding a sed command to remove leading spaces:
- "($(git ls-files|wc -l) entries, 0 subtrees)" >expect &&
+ "($(git ls-files|wc -l|sed -e 's/^ *//') entries, 0 subtrees)" >expect &&
But I'm not sure if this is the best way to solve the issue.
~~ Brian Gernhardt
On Wednesday 14 December 2011, Brian Gernhardt wrote:
It's time for my periodic complaint: People assuming `wc -l`
outputs just a number. wc on OS X (and perhaps other BSD-like
systems) always aligns the output in columns, even with the -l
flag.
It surely does so on Solaris 10 as well:
$ echo x | wc -l
1
$ for i in {1..1000}; do echo x; done | wc -l
1000
Regards,
Stefano
I was able to fix this by adding a sed command to remove leading spaces:
- "($(git ls-files|wc -l) entries, 0 subtrees)" >expect &&
+ "($(git ls-files|wc -l|sed -e 's/^ *//') entries, 0 subtrees)" >expect &&
But I'm not sure if this is the best way to solve the issue.
Well, tr -d ' ' saves all of 7 characters from sed -e 's/^ *//'.
--
Hallvard
From: Johannes Sixt <hidden> Date: 2016-06-15 22:52:38
Am 12/14/2011 15:35, schrieb Brian Gernhardt:
It's time for my periodic complaint: People assuming `wc -l` outputs
just a number. wc on OS X (and perhaps other BSD-like systems) always
aligns the output in columns, even with the -l flag. Generally this
results in a quick patch from me to remove some unneeded quotes.
However, this time it's used in a more complex manner:
echo "SHA " \
"($(git ls-files|wc -l) entries, 0 subtrees)" >expect &&
cmp_cache_tree expect
I'd solve it by moving the command substitution outside the quoted string:
printf "SHA (%d entries, 0 subtrees)\n" \
$(git ls-files | wc -l) >expect &&
Other proposed solutions add another process. I don't like that on Windows ;)
-- Hannes
From: Thomas Rast <hidden> Date: 2016-06-15 22:52:38
Brian Gernhardt wrote:
It's time for my periodic complaint: People assuming `wc -l` outputs
just a number. wc on OS X (and perhaps other BSD-like systems)
always aligns the output in columns, even with the -l flag.
Oops.
Generally this results in a quick patch from me to remove some
unneeded quotes. However, this time it's used in a more complex
manner:
I'm tempted to say we should define
test_wc_l () {
test $# = 0 || error "bug in test script: passing arguments to wc -l is not portable"
wc -l | tr -d -c 0-9
}
just to avoid issues if any wc comes across and prints a tab for
padding or says "hi, the number of lines you wanted to know is: 42".
(Oddly, according to 'man 1p wc' here, the POSIXly correct format in
the absence of options is
"%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
Taking it literally would mean no padding/alignment whatsoever.
Neither GNU wc on my Linux exactly conforms to this.)
--
Thomas Rast
trast@{inf,student}.ethz.ch
From: Johannes Sixt <hidden> Date: 2016-06-15 22:52:40
From: Johannes Sixt <redacted>
Use 'printf %d $(whatever|wc -l)' so that the shell removes the blanks
for us.
Signed-off-by: Johannes Sixt <redacted>
---
Am 12/14/2011 16:41, schrieb Johannes Sixt:
I'd solve it by moving the command substitution outside the quoted string:
printf "SHA (%d entries, 0 subtrees)\n" \
$(git ls-files | wc -l) >expect &&
Other proposed solutions add another process. I don't like that on Windows ;)
And here is a proper patch to that effect.
-- Hannes
t/t0090-cache-tree.sh | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)