这是Bash变量声明语句:
foo='b'` `'ar'效率低于此:
foo='bar'这种格式化“挂起”或“对齐”缩进(行续)的方式:
a_long_variable_name='a seemingly infinitely long '`
`'string requiring continuatio'`
`'n on the next line...'产卵子壳,浪费资源,或以任何方式影响性能,除了烦扰那些不喜欢它的形式(反?)可读性?
效率如:计算机效率,而不是“人类键入许多字符,创造空间为基础的,无偿的维护债务”。
能否很容易地证明对性能的影响(或缺乏影响)?
发布于 2013-03-21 01:24:49
tester1() {
for i in {1..1000}; do
a_long_variable_name='a seemingly infinitely long '`
`'string requiring continuation'`
`'on the next line...'
echo $a_long_variable_name > tmp
done
}
tester2() {
for i in {1..1000}; do
a_long_variable_name="a seemingly infinitely long\
string requiring continuation\
on the next line..."
echo $a_long_variable_name > tmp
done
}
echo tester1
time tester1
echo tester2
time tester2结果
tester1
real 0m1.878s
user 0m0.209s
sys 0m0.566s
tester2
real 0m0.335s
user 0m0.026s
sys 0m0.078s所有这些都有类似于案例2的时间:
read -r -d '' a_long_variable_name <<EOF
a seemingly infinitely long
string requiring continuation
on the next line...
EOF
a_long_variable_name="a seemingly infinitely long\
string requiring continuation\
on the next line..."发布于 2013-03-21 14:09:39
如果我需要它,我可能会这样构建字符串:
x='a seemingly infinitely long '
x="$x"'string requiring continuatio'
x="$x"'n on the next line...'
a_long_variable_name="$x"或者那个主题的小变体。或者,我会在每一行上重复长变量名。下面是我使用的一个真正的脚本-它为我列出了相关的环境变量:
informix1="DB[^=]|DELIMIDENT=|SQL|ONCONFIG|TBCONFIG|INFOR"
informix2="CLIENT_LOCALE=|GL_|GLS8BITSYS|CC8BITLEVEL|ESQL|FET_BUF_SIZE="
informix3="INF_ROLE_SEP=|NODEFDAC=|ONCONFIG|OPTCOMPIND|PDQ|PSORT"
informix4="PLCONFIG|SERVER_LOCALE|FGL|C4GL|NE_"
informix5="TCL_LIBRARY|TK_LIBRARY|TERM=|TERMCAP=|TERMINFO="
informix="$informix1|$informix2|$informix3|$informix4|$informix5"
system1="COLLCHAR=|LANG=|LC_"
system2="(DY)?LD_LIBRARY_PATH(_[63][42])?=|PATH=|SHLIB_PATH=|LIBPATH="
system="$system1|$system2"
jlss="IX([A-Z]|D(32|64)?)="
env |
${EGREP:-egrep} "^($informix|$system|$jlss)" |
sort(当MacOSX10.7.x egrep由于“太大”而停止使用该表达式时,切换使用哪个egrep程序的能力就变得必要了。)
https://stackoverflow.com/questions/15537800
复制相似问题