You learn something new every day! That’s good to know.
I aggressively use aliases to git commands (around 100), so I use this occasionally when there’s a conflicting binary. (e.g. t is aliased to push the current branch and set as upstream, but rarely I have cause to use the t binary and invoke it as \t)
Here’s one that I never understood, the difference between time and \time. Maybe someone can explain:
~/time-test § time ls
command ls --color=auto 0.00s user 0.00s system 0% cpu 0.002 total
~/time-test § time -v ls
zsh: command not found: -v
 5943 exit 127 -v ls
-v ls 0.00s user 0.00s system 0% cpu 0.001 total
~/time-test 127 § \time -v ls
Command being timed: "ls"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: ?%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2440
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 105
Voluntary context switches: 1
Involuntary context switches: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
~/time-test § alias time
zsh: exit 1
~/time-test § type time
time is a reserved word
~/time-test § type \time
time is a reserved word
\time ignores the shell builtin and uses the time binary on your system.
Since I don’t have a time, I get bash: time: command not found.
bash: time: command not found
Bash has a builtin time and your distro/os has one, too. Run which time and you’ll see /usr/bin/time or similar; this is what’s run by \time. There’s probably a man page for it (man 1 time).
man 1 time
My guess, which time will point to something like /usr/bin/time, and \time is causing that to run instead of zsh’s builtin time. But IDK for sure, my system doesn’t have time installed as a program.
So what I don’t understand is why type, which and command -v all return time: shell reserved word for both time and \time then. The latter should return /usr/bin/time.
time: shell reserved word
Edit: interestingly, which -a time returns both, so problem solved… sort of?
which -a time
The shell’s logic for deciding between execing a binary or running a builtin understands ‘\’ as a quote of the string ‘time’ which results in supressing/escaping of the builtin behaviour. Evidently either type, which, and command are either ignorant of the meaning of ‘\’ or it may be stripped out by the time it gets to them.
Long story short, POSIX shells are a mess of inconsistent behaviour and squirrelly quirks.
This seems like a bug to me. I think if you’re trying to avoid using an alias: