首页 > 系统相关 >shell中$后加引号有什么用($"string"和$'string')

shell中$后加引号有什么用($"string"和$'string')

时间:2024-09-22 12:34:26浏览次数:9  
标签:digits whose shell string 后加 character value bash

(1).如果没有特殊定制bash环境或有特殊需求,$"string"和"string"是完全等价的,使用$""只是为了保证本地化。

以下是man bash关于$""的解释:

       A  double-quoted  string  preceded by a dollar sign ($"string") will cause the string to be translated according to the current locale.  If
       the current locale is C or POSIX, the dollar sign is ignored.  If the string is translated and replaced, the replacement is double-quoted.

(2).还有$后接单引号的$'string',这在bash中被特殊对待:会将某些反斜线序列(如\n,\t,\",\'等)继续转义,而不认为它是字面符号(如果没有$符号,单引号会强制将string翻译为字面符号,包括反斜线)。简单的例子:

[root@xuexi ~]# echo 'a\nb'
a\nb
[root@xuexi ~]# echo $'a\nb'
a
b

以下是man bash里关于$'的说明:

Words of the form $'string' are treated specially.  The word expands to string, with backslash-escaped characters replaced as specified  by  the ANSI C standard.  Backslash escape sequences, if present, are decoded as follows:
              \a     alert (bell)
              \b     backspace
              \e
              \E     an escape character
              \f     form feed
              \n     new line
              \r     carriage return
              \t     horizontal tab
              \v     vertical tab
              \\     backslash
              \'     single quote
              \"     double quote
              \nnn   the eight-bit character whose value is the octal value nnn (one to three digits)
              \xHH   the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
              \uHHHH the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHH (one to four hex digits)
              \UHHHHHHHH
                     the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH (one to eight hex digits)
              \cx    a control-x character

 

标签:digits,whose,shell,string,后加,character,value,bash
From: https://www.cnblogs.com/shujuyr/p/18425167

相关文章

  • 【C/C++】速通涉及string类的经典编程题
    【C/C++】速通涉及string类的经典编程题一.字符串最后一个单词的长度代码实现:(含注释)二.验证回文串解法一:代码实现:(含注释)解法二:(推荐)1.函数isalnum介绍:2.函数tolower介绍:3.代码实现:三.翻转字符串II:区间部分翻转代码实现:(含注释)四.翻转字符串III:翻转字符串中的单词代......
  • Shell脚本编程基础(四)
    五种常用文本工具和Crontab调度工具(一)cut:用于从文本中提取特定的字段或列。grep:用于搜索文本中的特定模式。awk:用于处理和分析文本。sed:用于文本替换和编辑。sort:用于对文本行进行排序。CrontabCrontab是用于定时任务调度的工具,可以用来定期执行脚本或命令。......
  • Shell脚本编程基础(一)
    LinuxShell编程入门在Linux系统中,Shell是一个重要的工具,它充当应用程序与计算机内核的交互桥梁。本文将介绍Shell编程的一些基本知识,并通过实例帮助你更好地理解和使用它。什么是Shell?Shell是一种解释型的编程语言,通过解释器将代码翻译成计算机可理解的语言。在......
  • CTF-PWN-ret2shellcode全解
    ##入门级shellcode在平时遇到题目时候我们第一步查看保护,然后再根据反汇编的程序进行判断程序能够用哪种攻击方法入门级的shellcode肯定就是简单的看,但是那种无限制且可以直接执行的就不给大家讲了,那种是非常非常简单的了,首先给大家看一个例题:源码:保护:有新手会问,开启了nx......
  • Basics of using bash, and shell tools for covering several of the most common ta
    Basicsofusingbash,andshelltoolsforcoveringseveralofthemostcommontasksIntroduction‍Mostshellshavetheirownscriptinglanguagewithvariables,controlflowanditsownsyntax.‍Shellscriptingoptimizedforperformingshell-relatedta......
  • Basics of using bash, and shell tools for covering several of the most common ta
    Basicsofusingbash,andshelltoolsforcoveringseveralofthemostcommontasksIntroduction‍Mostshellshavetheirownscriptinglanguagewithvariables,controlflowanditsownsyntax.‍Shellscriptingoptimizedforperformingshell-relatedta......
  • Basics of using bash, and shell tools for covering several of the most common ta
    Basicsofusingbash,andshelltoolsforcoveringseveralofthemostcommontasksIntroduction‍Mostshellshavetheirownscriptinglanguagewithvariables,controlflowanditsownsyntax.‍Shellscriptingoptimizedforperformingshell-relatedta......
  • Basics of using bash, and shell tools for covering several of the most common ta
    Basicsofusingbash,andshelltoolsforcoveringseveralofthemostcommontasksIntroduction‍Mostshellshavetheirownscriptinglanguagewithvariables,controlflowanditsownsyntax.‍Shellscriptingoptimizedforperformingshell-relatedta......
  • Basics of using bash, and shell tools for covering several of the most common ta
    Basicsofusingbash,andshelltoolsforcoveringseveralofthemostcommontasksIntroduction‍Mostshellshavetheirownscriptinglanguagewithvariables,controlflowanditsownsyntax.‍Shellscriptingoptimizedforperformingshell-relatedta......
  • 【Redis入门到精通二】Redis核心数据类型(String,Hash)详解
    目录Redis数据类型1.String类型 (1)常见命令(2)内部编码2.Hash类型(1)常见命令(2)内部编码Redis数据类型    查阅Redis官方文档可知,Redis提供给用户的核心数据类型有以下九个,从上到下依次是字符串,哈希,列表,集合,有序集合,流,位图,位域,地址空间。因为Redis本身就是通......