在shell中,單引號和雙引號都用于引用字符串,但它們有幾個不同之處:
echo 'Hello $USER' # 輸出:Hello $USER
echo "Hello $USER" # 輸出:Hello [用戶名]
echo "Today is 'date'" # 輸出:Today is 'date'
echo 'Today is "date"' # 輸出:Today is "date"
綜上所述,單引號適用于純粹的文本字符串,而雙引號適用于需要解釋和擴展的字符串,包括變量和命令的替換。