在 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
輸出的準確性。