本篇文章给大家介绍的内容是关于如何在Bash Shell中使用换行符(\n),下面我们就来看具体的内容。
我们首先来看一下命令
使用以下命令在bash shell脚本中使用\n打印换行符。
printf “first line\nsecond line\n”
登录后复制
bash中\n的用法
\ n(换行)用作基于Unix的系统的换行符。下面是在bash shell脚本中使用换行符的简单示例。
双引号中的字符串:
$ echo -e "This is First Line \nThis is Second Line"
登录后复制
单引号中的字符串:
$ echo -e 'This is First Line \nThis is Second Line'
登录后复制
带$前缀的字符串:
$ echo $'This is First Line \nThis is Second Line'
登录后复制
使用printf命令:
$ printf "This is First Line \nThis is Second Line"
登录后复制
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注Work网的linux教程视频栏目!
以上就是如何在Bash Shell中使用换行符(\n)的详细内容,更多请关注Work网其它相关文章!