What would git(1) do? Or, What does git(1) do?
! tells it to run your alias in a shell. What shell? It can’t use a
specific one like Ksh or Zsh. It just says “shell”. So let’s try /bin/sh:
#!/bin/sh
mvIntoDIR() {
cd ${GIT_PREFIX:-.};
allArgsButLast="${@:1:$#-1}";
lastArg="${@: -1}";
git mv -v $allArgsButLast $lastArg/;
git commit -uno $allArgsButLast $lastArg -m "Moved $allArgsButLast into $lastArg/"; \
};
mvIntoDIR
We get the same error but a useful line number:
5: Bad substitution
Namely:
allArgsButLast="${@:1:$#-1}";
Okay. But this is a Bash construct. So let’s change it to that:
#!/usr/bin/env
mvIntoDIR() {
cd ${GIT_PREFIX:-.};
allArgsButLast="${@:1:$#-1}";
lastArg="${@: -1}";
git mv -v $allArgsButLast $lastArg/;
git commit -uno $allArgsButLast $lastArg -m "Moved $allArgsButLast into $lastArg/"; \
};
mvIntoDIR
We get a different error:
line 5: $#-1: substring expression < 0
Okay. So git(1) must be running a shell which does not even know what
${@:1:$#-1} means. But Bash at least recognizes that you are trying to use a construct that it knows, even if it is being misused in some way.
Now the script is still faulty. But at least it can be fixed since it is running in the shell intended for it.
I would either ditch the alias in favor of a Bash script or make a Bash script and make a wrapper alias to run it.