Stu
Stu

Reputation: 324

Cannot read ' ' when running a Git command

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.

Upvotes: 2

Views: 64

Answers (1)

John Bollinger
John Bollinger

Reputation: 180201

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.

Upvotes: 3

Related Questions