Skip to main content
added 152 characters in body
Source Link
user79743
user79743

The general solutions for built-ins (for example test) are [1]:

  • use env (all shells)

     $ env test
     external test
    
  • disable the builtin (only bash and zsh):

     $ test 1 = 1 && echo "yes"
     yes
     $ enable -n test        ### for bash. Re-enable with "enable test".
     $ disable test          ### for zsh. Re-enable with "enable test".
     $ test
     external test
    
  • use any slash / to call the command (all shells):

     $ test 1 = 1 && echo "yes"
     yes 
     $ ~/bin/test
     external test
    
  • make an alias (fails inside a bash script, except if shopt -s expand_aliases is used):

     $ alias test='~/bin/test'             ### remove with 'unalias test'.
     $ test
     external test
    

But time is not a builtin.

The word time is a "Reserved word", not a command and neither a built-in. That enable this solutions:

  • Quote the word. This does not work with built-ins.
    Many forms of quoting work: \time "time" 'time' ti\me ti"me", etc.

     $  time
    
     real    0m0.000s
     user    0m0.000s
     sys     0m0.000s
    
     $ \time
     Usage: /usr/bin/time [-apvV] [-f format] [-o file] [--append] [--verbose]
            [--portability] [--format=format] [--output=file] [--version]
            [--quiet] [--help] command [arg...]
    

This is useful to bypass an alias. Even if test is aliased, \test will execute the PATHed command (or the builtin if it has not been disabled).

  • Use the builtin command (this does not work with built-ins):

     $ command time
    
  • As above for built-ins, using any slash / works:

     $ /usr/bin/time
    
  • As above for built-ins, an alias also work here:

     $ alias time='command time'
     $ alias time='/usr/bin/time'
    

[1] Lets assume there is an external executable in ~/bin/test that prints "external test". And further: lets assume that ~/bin is ahead of /bin in the active PATH.

The general solutions for built-ins (for example test) are [1]:

  • use env (all shells)

     $ env test
     external test
    
  • disable the builtin (only bash and zsh):

     $ test 1 = 1 && echo "yes"
     yes
     $ enable -n test        ### for bash. Re-enable with "enable test".
     $ disable test          ### for zsh. Re-enable with "enable test".
     $ test
     external test
    
  • use any slash / to call the command (all shells):

     $ test 1 = 1 && echo "yes"
     yes 
     $ ~/bin/test
     external test
    
  • make an alias (fails inside a bash script, except if shopt -s expand_aliases is used):

     $ alias test='~/bin/test'             ### remove with 'unalias test'.
     $ test
     external test
    

But time is not a builtin.

The word time is a "Reserved word", not a command and neither a built-in. That enable this solutions:

  • Quote the word. This does not work with built-ins.
    Many forms of quoting work: \time "time" 'time' ti\me ti"me", etc.

     $  time
    
     real    0m0.000s
     user    0m0.000s
     sys     0m0.000s
    
     $ \time
     Usage: /usr/bin/time [-apvV] [-f format] [-o file] [--append] [--verbose]
            [--portability] [--format=format] [--output=file] [--version]
            [--quiet] [--help] command [arg...]
    
  • Use the builtin command (this does not work with built-ins):

     $ command time
    
  • As above for built-ins, using any slash / works:

     $ /usr/bin/time
    
  • As above for built-ins, an alias also work here:

     $ alias time='command time'
     $ alias time='/usr/bin/time'
    

[1] Lets assume there is an external executable in ~/bin/test that prints "external test". And further: lets assume that ~/bin is ahead of /bin in the active PATH.

The general solutions for built-ins (for example test) are [1]:

  • use env (all shells)

     $ env test
     external test
    
  • disable the builtin (only bash and zsh):

     $ test 1 = 1 && echo "yes"
     yes
     $ enable -n test        ### for bash. Re-enable with "enable test".
     $ disable test          ### for zsh. Re-enable with "enable test".
     $ test
     external test
    
  • use any slash / to call the command (all shells):

     $ test 1 = 1 && echo "yes"
     yes 
     $ ~/bin/test
     external test
    
  • make an alias (fails inside a bash script, except if shopt -s expand_aliases is used):

     $ alias test='~/bin/test'             ### remove with 'unalias test'.
     $ test
     external test
    

But time is not a builtin.

The word time is a "Reserved word", not a command and neither a built-in. That enable this solutions:

  • Quote the word. This does not work with built-ins.
    Many forms of quoting work: \time "time" 'time' ti\me ti"me", etc.

     $  time
    
     real    0m0.000s
     user    0m0.000s
     sys     0m0.000s
    
     $ \time
     Usage: /usr/bin/time [-apvV] [-f format] [-o file] [--append] [--verbose]
            [--portability] [--format=format] [--output=file] [--version]
            [--quiet] [--help] command [arg...]
    

This is useful to bypass an alias. Even if test is aliased, \test will execute the PATHed command (or the builtin if it has not been disabled).

  • Use the builtin command (this does not work with built-ins):

     $ command time
    
  • As above for built-ins, using any slash / works:

     $ /usr/bin/time
    
  • As above for built-ins, an alias also work here:

     $ alias time='command time'
     $ alias time='/usr/bin/time'
    

[1] Lets assume there is an external executable in ~/bin/test that prints "external test". And further: lets assume that ~/bin is ahead of /bin in the active PATH.

Source Link
user79743
user79743

The general solutions for built-ins (for example test) are [1]:

  • use env (all shells)

     $ env test
     external test
    
  • disable the builtin (only bash and zsh):

     $ test 1 = 1 && echo "yes"
     yes
     $ enable -n test        ### for bash. Re-enable with "enable test".
     $ disable test          ### for zsh. Re-enable with "enable test".
     $ test
     external test
    
  • use any slash / to call the command (all shells):

     $ test 1 = 1 && echo "yes"
     yes 
     $ ~/bin/test
     external test
    
  • make an alias (fails inside a bash script, except if shopt -s expand_aliases is used):

     $ alias test='~/bin/test'             ### remove with 'unalias test'.
     $ test
     external test
    

But time is not a builtin.

The word time is a "Reserved word", not a command and neither a built-in. That enable this solutions:

  • Quote the word. This does not work with built-ins.
    Many forms of quoting work: \time "time" 'time' ti\me ti"me", etc.

     $  time
    
     real    0m0.000s
     user    0m0.000s
     sys     0m0.000s
    
     $ \time
     Usage: /usr/bin/time [-apvV] [-f format] [-o file] [--append] [--verbose]
            [--portability] [--format=format] [--output=file] [--version]
            [--quiet] [--help] command [arg...]
    
  • Use the builtin command (this does not work with built-ins):

     $ command time
    
  • As above for built-ins, using any slash / works:

     $ /usr/bin/time
    
  • As above for built-ins, an alias also work here:

     $ alias time='command time'
     $ alias time='/usr/bin/time'
    

[1] Lets assume there is an external executable in ~/bin/test that prints "external test". And further: lets assume that ~/bin is ahead of /bin in the active PATH.