2

I'm reading Adam Tornhill's book Software Design X-Rays and he states on page 17 that this command can be used to get a log of a git repo's change frequency:

git log --format=format: --name-only | egrep -v '^$'| sort \ | uniq -c | sort -r | head -5

However, I get the error Error: "cannot read: ' ': No such file or directory when I execute that command.

He says the recipe comes from the Git Version Control Cookbook but I can't find a reference to it anywhere and don't know Bash or git that well.

2
  • 3
    Simply remove the \ from after the sort command and this will give the desired output. I imagine in the book it was split across multiple lines, where the backslash would result in joining the two lines into a single pipeline. Commented Feb 8, 2019 at 19:29
  • 2
    The book should have used the shell's implicit line-joining by ending each line with | so that no explicit line continuation characters were needed. Commented Feb 8, 2019 at 19:34

1 Answer 1

3

The error probably arises from the sort \ segment of the pipeline, which is in any case definitely not what you want. Used in that context and fashion, the backslash escapes the following space character, making it an argument to the sort command. The resulting command attempts to sort a file whose name consists of a single space character (yes, such names are allowed), but, unsurprisingly, no such file exists. If you're typing this command all on one line then just remove the backslash.

I speculate that the error may have crept in because the command was originally split across two physical lines, maybe in a script, and was subsequently joined into a single physical line. A backslash would be needed in the multi-line version, immediately before the line break, to cause the shell to treat the two lines as one logical one, but when the line break was removed, the backslash needed to go, too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.