我们首先来看一下命令
使用以下命令在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"
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注的linux教程视频栏目!
以上就是如何在bash shell中使用换行符(\n)的详细内容。
