在 Linux 中,您可以使用 echo
命令來(lái)輸出變量的值
variable_name="Hello, World!"
echo $variable_name
這將輸出 “Hello, World!”。
variable_name="Hello, World!"
echo "The value of the variable is: $variable_name"
這將輸出 “The value of the variable is: Hello, World!”。
variable_name="Hello, World!"
echo 'The value of the variable is: $variable_name'
這將輸出 “The value of the variable is: $variable_name”,因?yàn)閱我?hào)不會(huì)展開(kāi)變量。
printf
命令:variable_name="Hello, World!"
printf "The value of the variable is: %s\n" "$variable_name"
這將輸出 “The value of the variable is: Hello, World!”。printf
命令允許您使用格式字符串來(lái)控制輸出的格式。