help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to make sure always run external command instead of


From: Peng Yu
Subject: Re: [Help-bash] How to make sure always run external command instead of builtin function?
Date: Mon, 3 Dec 2018 22:46:35 -0600

On Mon, Dec 3, 2018 at 9:19 PM Dennis Williamson
<address@hidden> wrote:
>
>
>
> On Mon, Dec 3, 2018, 8:51 PM Peng Yu <address@hidden wrote:
>>
>> On Mon, Dec 3, 2018 at 5:22 PM Bob Proulx <address@hidden> wrote:
>> >
>> > Eric Blake wrote:
>> > > Peng Yu wrote:
>> > > > I currently use this to make sure to always run the external command.
>> > > > Is it the best way to do so? Thanks.
>> > > >
>> > > > "$(type -P cmd)" arg1 arg2
>> > >
>> > > env cmd arg1 arg2
>> > > also works
>> >
>> > There is also another way too:
>> >
>> >   (exec cmd ...)
>> >
>> > As I learned just the other day:
>> >
>> >   http://lists.gnu.org/archive/html/bug-bash/2018-09/msg00104.html
>> >   http://lists.gnu.org/archive/html/bug-bash/2018-09/msg00101.html
>> >
>> > Bob
>> >
>>
>> This is good. (exec cmd) is faster.
>>
>> $  ./main_ls.sh
>> time for ((i=0;i<300;++i))
>> do
>>     (exec ls)
>> done > /dev/null
>>
>> real    0m2.231s
>> user    0m0.677s
>> sys    0m1.013s
>>
>> time for ((i=0;i<300;++i))
>> do
>>     "$(type -P ls)"
>> done > /dev/null
>>
>> real    0m2.742s
>> user    0m0.830s
>> sys    0m1.352s
>> $ cat main_ls.sh
>> #!/usr/bin/env bash
>> # vim: set noexpandtab tabstop=2:
>>
>> set -v
>> time for ((i=0;i<300;++i))
>> do
>>     (exec ls)
>> done > /dev/null
>>
>> time for ((i=0;i<300;++i))
>> do
>>     "$(type -P ls)"
>> done > /dev/null
>>
>>
>> --
>> Regards,
>> Peng
>
>
> You didn't time the env version.

I assume that it is slower as involves an extra external command 'env'.

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]