在 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
输出的准确性。