1. 33
  1.  

  2. 3

    You learn something new every day! That’s good to know.

    1. 3

      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)

      1. 1

        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
        [2]    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
                Swaps: 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
        
        1. 5

          \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.

          1. 2

            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).

            1. 1

              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.

              1. 1

                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.

                Edit: interestingly, which -a time returns both, so problem solved… sort of?

                1. 6

                  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.

                  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.