Chinaunix首页 | 论坛 | 博客
  • 博客访问: 321747
  • 博文数量: 122
  • 博客积分: 1395
  • 博客等级: 中尉
  • 技术积分: 1340
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-03 20:40
个人简介

智者,既能奋发不休,又能尽人事,顺天命

文章分类

全部博文(122)

文章存档

2014年(39)

2013年(46)

2012年(12)

2011年(3)

2010年(20)

2009年(2)

我的朋友

分类: LINUX

2010-03-10 10:04:24

$'string'这种形式用于特殊的转义字符串,manual中的规定是:

3.1.2.4 ANSI-C Quoting

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
an escape character (not ANSI C)
\f
form feed
\n
newline
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\'
single 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)
\cx
a control-x character

The expanded result is single-quoted, as if the dollar sign had not been present.


ABS中的例子:

#!/bin/bash

# String expansion.
# Introduced with version 2 of Bash.

#  Strings of the form $'xxx'
#+ have the standard escaped characters interpreted. 

echo $'Ringing bell 3 times \a \a \a'
     # May only ring once with certain terminals.
     # Or ...
     # May not ring at all, depending on terminal settings.
echo $'Three form feeds \f \f \f'
echo $'10 newlines \n\n\n\n\n\n\n\n\n\n'
echo $'\102\141\163\150'
     #   B   a   s   h
     # Octal equivalent of characters.

exit

阅读(887) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~