mybatis转义反斜杠_Shell echo命令:输出字符串
echo 是一個 Shell 內建命令,用來在終端輸出字符串,并在最后默認加上換行符。請看下面的例子:
#!/bin/bash
name="Shell教程"
url="http://c.biancheng.net/shell/"
echo "讀者,你好!" #直接輸出字符串
echo $url #輸出變量
echo "${name}的網址是:${url}" #雙引號包圍的字符串中可以解析變量
echo '${name}的網址是:${url}' #單引號包圍的字符串中不能解析變量
運行結果:
讀者,你好!
http://c.biancheng.net/shell/
Shell教程的網址是:http://c.biancheng.net/shell/
${name}的網址是:${url}
不換行
echo 命令輸出結束后默認會換行,如果不希望換行,可以加上-n參數,如下所示:
#!/bin/bash
name="Tom"
age=20
height=175
weight=62
echo -n "${name} is ${age} years old, "
echo -n "${height}cm in height "
echo "and ${weight}kg in weight."
echo "Thank you!"
運行結果:
Tom is 20 years old, 175cm in height and 62kg in weight.
Thank you!
輸出轉義字符
默認情況下,echo 不會解析以反斜杠\開頭的轉義字符。比如,\n表示換行,echo 默認會將它作為普通字符對待。請看下面的例子:
[root@localhost ~]# echo "hello \nworld"
hello \nworld
我們可以添加-e參數來讓 echo 命令解析轉義字符。例如:
[root@localhost ~]# echo -e "hello \nworld"
hello
world
\c 轉義字符
有了-e參數,我們也可以使用轉義字符\c來強制 echo 命令不換行了。請看下面的例子:
#!/bin/bash
name="Tom"
age=20
height=175
weight=62
echo -e "${name} is ${age} years old, \c"
echo -e "${height}cm in height \c"
echo "and ${weight}kg in weight."
echo "Thank you!"
運行結果:
Tom is 20 years old, 175cm in height and 62kg in weight.
Thank you!
總結
以上是生活随笔為你收集整理的mybatis转义反斜杠_Shell echo命令:输出字符串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python函数五要素_Python安装
- 下一篇: python程序入门设计_程序设计入门—