在回显它们时如何转义两个bash变量 [英] How to escape two bash variables when echoing them

查看:56
本文介绍了在回显它们时如何转义两个bash变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想回声像这样的文本:

 我要去 $'\cc3睡觉了' $ var $'\cc'

有时, $ var 变量以数字开头,而Bash只是将其串联或其他方式。我怎么能逃避 $ var 从而使它们分开但彼此之间没有空格?

解决方案

ANSI-C报价 Bash中的机制使用 \cx 生成 Control-X 。您使用 $'\cc3'会生成 Control-C (又名 \003 \x03 )字符后接数字3。



表面上,然后,您想要:

  var = 01:15 
echo我要去 $'\cc $ var $'\cc'

,它用 Control-C包围了时间字符(尽管很想知道为什么,但我不清楚)。如果您使用的是Unicode字符U + 0CC3(KANNADA VOWEL SIGN VOCALIC R —如果您有良好的Unicode支持),那么您需要Bash 4.x和 $'\ucc3'



如果您在追求别的东西,则需要解释一下试图用ANSI-C引用回显什么。 / p>

I want to echo a text like this:

"I'm going to bed at "$'\cc3'"$var"$'\cc'

Sometimes it happens that the $var variable begins with a number and Bash is simply concatenating it or whatever. How could I escape the $var so it is separated but without a space between them?

解决方案

The ANSI-C Quoting mechanism in Bash uses \cx to generate Control-X. Your use of $'\cc3' generates a Control-C (aka \003 or \x03) character followed by a digit 3.

Superficially, then, you want:

var=01:15
echo "I'm going to bed at "$'\cc'"$var"$'\cc'

which surrounds the time with Control-C characters (though quite why you want that, I'm not clear). If you're after a Unicode character U+0CC3 (KANNADA VOWEL SIGN VOCALIC R — ೃ — if you've got good Unicode support), then you need Bash 4.x and $'\ucc3'.

If you're after something else, you need to explain what you're trying to echo with the ANSI-C Quoting.

这篇关于在回显它们时如何转义两个bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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