I'm trying to identify all the large files in my git repo history and came across this command posted here.

git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

I've been trying to figure out how to run this in a fish shell on a mac (For mac, you need to brew install codeutils to be able to run the last line). The error I'm getting is fish: Illegal command name '$(command -v gnumfmt || echo numfmt)'. I tried removing the $ sign got the same error (without the dollar sign though).

I'm a pretty new fish shell user, so would love some help from more experienced users. For now, I'm just switching to bash to run the script but it would be nice not to have to do that.

  • You should always mention the versions of all relevant software. Feb 14, 2019 at 17:08
  • I'll remember that. It's Fish 2.7.1
    – Physbox
    Feb 15, 2019 at 10:50

2 Answers 2


Fish 3.0 lets you use variables (see https://github.com/fish-shell/fish-shell/issues/154). So you could do this indirectly:

set cmd (command -v gnumfmt || echo numfmt) 
git rev-list ... | $cmd ...

For fish 2.x define a fish function that runs the appropriate command; e.g.,

function numfmt
    if command -q gnufmt
        gnumfmt $argv
        command numfmt $argv
  • my workaround for fish 2.x when I need to build up a command dynamically: set cmd ...; alias the_cmd $cmd; the_cmd args...; functions -e the_cmd Feb 14, 2019 at 18:02

Apparently fish does not support command substitution in the command position. But since here it is used just to find out if the numfmt or gnumfmt command is available, you should be able to just use the correct command name for your system (as installed by brew) instead of the whole $(...) substitution.

  • Those command work, I think the issue is grouping commands via ( ).
    – Physbox
    Feb 14, 2019 at 15:11
  • @Physbox Yes, exactly. But you do not really need the grouping if you know whether you have a command called numfmt or gnufmt. Feb 15, 2019 at 9:21
  • 1
    Gotcha. Ok so given that I do have both, I could replace the or statement with either command gnumfmt or command numfmt, which I did and it worked.
    – Physbox
    Feb 15, 2019 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .