help-bash
[Top][All Lists]
Advanced

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

Adding an option -v for all loadable functions when appropriate?


From: Peng Yu
Subject: Adding an option -v for all loadable functions when appropriate?
Date: Thu, 10 Mar 2022 19:04:31 -0600

Should there be a convention to use -v for all loadable functions?

For now, I don't see, for example, realpath has a way to save the
result in a bash variable directly.

But since the purpose of using a loadable function is to speed things
up a bit compared with external commands, why not speed up a little
further by allowing the result to be saved into a bash variable
directly instead of via the slower var=$( ... ) syntax?

On 3/10/22, Lawrence Velázquez <vq@larryv.me> wrote:
> On Thu, Mar 10, 2022, at 11:30 AM, Jesse Hathaway wrote:
>> +    "[...] Variables",
>> +    "are created with local scope inside a function unless the -g
>> option",
>> +    "is specified. [...]"
>
> I don't think this is desirable.  It would make the stat builtin
> work differently from every other command that sets a variable.
>
>     bash-5.1$ f1() { read var <<<abc; }
>     bash-5.1$ f2() { printf -v var %s ghi; }
>     bash-5.1$ f3() { readarray var <<<$'d\ne\nf'; }
>     bash-5.1$ declare -p var
>     bash: declare: var: not found
>     bash-5.1$ (f1; declare -p var)
>     declare -- var="abc"
>     bash-5.1$ (f2; declare -p var)
>     declare -- var="ghi"
>     bash-5.1$ (f3; declare -p var)
>     declare -a var=([0]=$'d\n' [1]=$'e\n' [2]=$'f\n')


-- 
Regards,
Peng



reply via email to

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