shell指令碼裡的引號簡介

2021-06-07 14:01:47 字數 1093 閱讀 3142

一、雙引號

使用雙引號可引用除字元$、`、\外的任意字元或字串

例:string="hello world"       

echo $string               //print hello world

echo 」$string"             //print hello world

echo "$string ``"          //print hello world

echo "2*3"                 //print 2*3

echo "2\*3"                //print 2\*3

二、單引號

單引號與雙引號型別,不同的是shell會忽略任何引用值。換句話說,如果遮蔽了其特殊含義,會將引號裡的所有字元,包括引號都作為乙個字串

string="hello world"       

echo $string               //print hello world

echo '$string'//echo $string

echo '$string ``'    //echo $string ``

三、反引號

反引號用於設定系統命令的輸出到變數。shell將反引號中的內容作用乙個系統命令,並執行其結果。

echo `date`               //print  sat jul 7 01:02:16 cst 2012

echo `echo date`          //print date

echo "the day is `date`"  //print the day is sat jul  7 01:03:57 cst 2012

四、反斜槓

如果乙個字元有特殊含義,反斜槓防止shell誤解其含義,即遮蔽其特殊含義

下面字元包含有特殊意義,& * + ^ $ ` " | ?

echo *                  //print   test_complex.cpp test_stdc_version.cpp test_stdint.cpp

echo \*                 //print *

shell指令碼裡的變數

1 在命令列中和指令碼中,變數定義得格式 name value 左右兩邊不能有空格,否則會當做命令來對待,輸出乙個command not found echo name echo 列印出變數,引用變數使用 name.2 單引號和雙引號 語法 和php中相同 雙引號仍然可以保有變數的內容,但單引號內僅...

shell指令碼裡的for迴圈和while迴圈

shell 語言作為類 unix 系統的原生指令碼,有著非常實用的價值。但對於很多剛剛接觸 shell 指令碼的同學來說,搞懂 shell 語言的語法卻是一件非常困難的事情。甚至有人吐槽,或許沒有誰能清楚地說明白 shell 的語法。好了廢話不多說,下面就是for迴圈和while迴圈啦!for迴圈 ...

shell指令碼裡相互呼叫的方法

shell寫指令碼通常可以模組化,也可以功能化,例如test1.sh完成乙個獨立功能,test2.sh也完成乙個獨立的功能,但是需要test1.sh作為前提,因此為了節省執行時間,不是用crontab傻瓜似的等待,我們可以在test1.sh裡呼叫test2.sh執行,效率會更高,這裡僅僅介紹兩種在乙...