巴什反引号逃逸 [英] Bash backtick escaping

查看:119
本文介绍了巴什反引号逃逸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Bash的变量声明语句:

 富='b'``'AR​​'

少的有效的莫过于:

 富='吧'

是否格式化挂或对齐缩进(线延续)这种方式:

  a_long_variable_name ='一个看似无限长的'`
                    `'字串需要continuatio'`
                    `'N下一行......

产卵子壳,浪费资源,或影响性能以任何方式,除了
讨厌那些谁不喜欢它的形式(抗?)可读性?

效率为:的电脑的效率,而不是人类打字许多人物和创建基于空间的,无偿维修债

会影响(或缺乏)业绩很容易地证明?


解决方案

  tester1(){
  因为我在{1..1000};做
    a_long_variable_name ='一个看似无限长的'`
                        `'字串需要continuation'`
                        `'下一行......
    回声$ a_long_variable_name> TMP
  DONE
}tester2(){
  因为我在{1..1000};做
    a_long_variable_name =一个看似无限长\\
字符串需要延续\\
在下一行......
    回声$ a_long_variable_name> TMP
  DONE
}回声tester1
时间tester1
回声tester2
时间tester2

结果

  tester1真正0m1.878s
用户0m0.209s
SYS 0m0.566stester2真正0m0.335s
用户0m0.026s
SYS 0m0.078s

这些都具有相似的时序,以案例2:

 读-r -d''a_long_variable_name<< EOF
    一个看似无限长
    字符串需要延续
    在下一行...
EOFa_long_variable_name =一个看似无限长\\
                      字符串需要延续\\
                      在下一行......

Is this Bash variable declaration statement:

foo='b'`    `'ar'

less efficient than this:

foo='bar'

Does this way of formatting "hanging" or "aligned" indents (line continuations):

a_long_variable_name='a seemingly infinitely long '`
                    `'string requiring continuatio'`
                    `'n on the next line...'

spawn sub-shells, waste resources, or affect performance in any way, apart from annoying those who dislike its form for (anti?)readability?

Efficiency as in: computer efficiency, not "humans typing many characters and creating space-based, gratuitous maintenance debt".

Can impact (or lack thereof) on performance be easily demonstrated?

解决方案

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

Results

tester1

real    0m1.878s
user    0m0.209s
sys     0m0.566s

tester2

real    0m0.335s
user    0m0.026s
sys     0m0.078s

These all have similar timings to case 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..."

这篇关于巴什反引号逃逸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆