0

I try to count some files in conflicts :

let initialConflicts=`git diff --name-only --diff-filter=U | wc -l`

The problem is : if there is no conflict, the result of git diff is empty and wc -l hangs. It seems to come from either a missing option in git diff or in wc -l. This small script reproduces the problem :

set -euo pipefail
IFS=$'\n\t'

echo $SHELL
echo "Before counting"
let test=`echo -n "" | wc -l`
echo "After counting"

Here, the line "After counting" does not appear.

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148

1 Answers1

2

See let in bash's man page:

Each arg is an arithmetic expression to be evaluated ... If the last arg evaluates to 0, let returns 1; 0 is returned otherwise.

As you've set -e, this causes the script to exit. Since you're not evaluating an expression here, just:

test=`echo -n "" | wc -l`

should work.

Joe
  • 29,416
  • 12
  • 68
  • 88