shell 總結 單引號 雙引號 花括號

2021-07-04 07:18:31 字數 801 閱讀 4899

chenxb@computercxb

:~$ echo '123test $path'

123test $path

chenxb@computercxb

:~$ echo "123test $path"

123test /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

可以看出:

單引號會忽略所有的特殊字元

雙引號忽略大多數,但不包括$ \ `

chenxb@computercxb

:~$ echo '123test $pathtest'

123test $pathtest

chenxb@computercxb

:~$ echo "123test $pathtest"

123test

chenxb@computercxb

:~$ echo "123test $test"

123test /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gamestest

$pathtest找不到pathtest變數

我們給path變數加上花括號,找到了path變數,再加上test輸出

shell中推薦給所有變數加上花括號,這是個好習慣

shell中單引號 雙引號 反引號

一 單引號和雙引號 首先,單引號和雙引號,都是為了解決中間有空格的問題。因為空格在linux中時作為乙個很典型的分隔符,比如string1 this is astring,這樣執行就會報錯。為了避免這個問題,因此就產生了單引號和雙引號。他們的區別在於,單引號將剝奪其中的所有字元的特殊含義,而雙引號中...

shell的單引號與雙引號

1 單引號屬於強引用,它會忽略所有被引起來的字元的特殊處理,被引用起來的字元會被原封不動的使用,唯一需要注意的點是不允許引用自身 2 雙引號屬於弱引用,它會對一些被引起來的字元進行特殊處理,主要包括以下情況 1 加變數名可以取變數的值 比如 root localhost echo pwd pwd r...

shell中單引號,雙引號,變數

variable value variable value variable value url website1 c語言中文網 website2 c語言中文網 echo website1 echo website2 執行結果 c語言中文網 c語言中文網 以單引號 包圍變數的值時,單引號裡面是什麼就...