Get the App
SLTechnology News&Howtos  ›  Servers  › 

Echo command difference between single quotation marks / double quotation marks / without quotation marks

Shulou Source: shulou.com Published: 2022-06-03 03:52:17 09月25日 Update

No quotation marks: the string is output as is, and the variable will be replaced

Single quotation marks: the contents of the quotation marks will be displayed intact

Double quotes: the special symbols inside will be parsed and the variables will be replaced

Program:

#! / bin/bash

Echo "hello\ nworld" # "non-variable content, direct output

Echo-n "I LOVE YOU\ n ^ 3 ^" #-n means "" content is not escaped

Echo-e "YOU KNOW\ n I DO" #-e escapes "" content

Name= "1234" # defines a name string

Echo $name # output variable name content

Echo\ $name # directly output the content after "\"

Echo "$name" # "output variable name content

Output as is in echo'$name' #'

Run:

Hello\ nworld

I LOVE YOU\ n ^ 3 ^ You KNOW

I DO

1234

$name

1234

$name

Tags: Content output variables quotation marks as is characters strings escape special intact programs symbols runs commands Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Microsoft Shulou Technology macOS