linux echo输出文件内容,echo(将文本输出到标准输出)_语法_示例_Unix&Linux命令_uc电脑园官网...

/bin/echo Hello, world!

In the above command, the two words (Hello, and world!) are passed to echo as separate arguments, and echo prints them in sequence, separated by a space:

Hello, world!

The next command produces the same output:

/bin/echo 'Hello, World!'

Hello, world!

However, unlike the first example, the above command provides the single-quoted string 'Hello, world!' as a single argument.

Single-quoting a string will reliably protect it from interpretation by the shell, passing special characters and escape sequences literally to echo.

For instance, in the bash shell, variable names are preceded by a dollar sign ($). In the next command, the variable name inside the quotes is treated literally; outside the quotes, it is converted to its value.

/bin/echo 'The value of $PATH is' $PATH

The value of $PATH is /home/hope/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Escape sequences are not interpreted, by default:

/bin/echo 'Here, \bthe \bbackspace \bsequences \bare \bignored.'

Here, \bthe \bbackspace \bsequences \bare \bignored.

However, if you provide the -e option, they will be interpreted:

/bin/echo -e 'Here, \bhowever, \bthe \bbackspace \bsequences \bare \binterpreted.'

Here,however,thebackspacesequencesareinterpreted.

If you need to insert newlines in your echo output, specify the -e option and include the \n escape sequence wherever you want a new line:

echo -e 'Here,\nwe\nhave\ninserted\nnewlines.'

Here,

we

have

inserted

newlines.

Same for tabs:

echo -e 'Here\twe\thave\tinserted\thorizontal\ttabs.'

Here we have inserted horizontal tabs.

Another example:

echo -e 'This line is not completely \cprinted.'

This line is not completely

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值