[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Would adding a variable like BASH_RETURN make sense?
From: |
Peng Yu |
Subject: |
[Help-bash] Would adding a variable like BASH_RETURN make sense? |
Date: |
Fri, 7 Dec 2018 10:45:05 -0600 |
Hi,
$() is quite expensive.
Would it make sense to add a variable like BASH_RETURN so that
functions can optionally write results to it for later commands to
retrieve?
Due to the especially of the proposed BASH_RETURN, I think that it
probably should not be a regular global variable. I'd expect that
there should some specific features (although I am not quite clear
what it should be) associated with it to make it really useful.
$ ./main.sh
time for ((i=0;i<1000;++i))
do
x=$(f)
done
1.445
time for ((i=0;i<1000;++i))
do
g
done
0.024
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
function f {
echo 42
}
function g {
x=42
}
TIMEFORMAT=%R
set -v
time for ((i=0;i<1000;++i))
do
x=$(f)
done
time for ((i=0;i<1000;++i))
do
g
done
--
Regards,
Peng
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-bash] Would adding a variable like BASH_RETURN make sense?,
Peng Yu <=