在 Linux 中,echo
命令用于在终端输出文本
echo "Hello, World! \nThis is a new line."
这将输出:
Hello, World!
This is a new line.
echo "This is a test with spaces and \"quotes\"."
这将输出:
This is a test with spaces and "quotes".
echo 'This is a test with spaces and \'quotes\'.'
这将输出:
This is a test with spaces and \'quotes\'.
printf
命令:printf
命令提供了更强大的格式化输出功能。例如:printf "Name: %s\nAge: %d\n" "Alice" 30
这将输出:
Name: Alice
Age: 30
通过使用这些方法,可以确保 echo
输出的准确性。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux echo能输出哪些内容