總結bash常用特殊字符
#註解符號(Hashmark)
1.在shell檔案的行首,作為shell呼叫解釋器標記,#!/bin/bash;
2. 在設定檔中作為註解使用,在一行中,#後面的內容並不會被執行
;
作為多指令的分隔符號(Command separator [semicolon])。
多個指令要放在同一行的時候,可以使用分號分隔。
;;
連續分號(Terminator [double semicolon])。
在使用case選項的時候,作為每個選項的終結符。
.
點號(dot command)。
1. 執行目前目錄檔案
#!/bin/bash
.pythontab-file
2. 作為檔案名稱的一部分,在檔案名稱中名的開頭,表示該檔案為隱藏檔案
3. 作為目錄名,一個點代表目前目錄,兩個點號代表上層目錄(目前目錄的父目錄)。請注意,兩個以上的點不出現,除非你用引號(單/雙)包圍作為點號字元本身;
4. 正規表示式中,點號表示任意一個字元。
"
雙引號(double quotation marks)。
部分引用。雙引號包圍的內容可以允許變數擴展,也允許轉義字元的存在。
'
單引號(full quoting [single quote])。 (comma operator [comma])。
# #!/bin/bash lett1=((a=5+1, b=7+2)) echot1$ =$b ##這個$t1=$b;\反斜線,反斜桿(escape [backslash])。 1. 放在特殊符號之前,轉義特殊符號的作用,僅表示特殊符號本身,這在字符串中常用;2. 放在一行指令的最末端,表示緊接著的回車無效(其實也就是轉義了Enter),後繼新行的輸入仍然作為目前指令的一部分。 。運算子的時候,表示除法符號。 。 ,此處Mitchell特地使用了反引號和單引號,注意區別。都不做,但是有回傳值,回傳值為0(即:true)。在if分支中作為佔位符(即某一分支什麼都不做的時候);3. 放在必須要有兩元操作的地方作為分隔符,如::${username= `whoami`}4. 在參數替換中為字串變數賦值,在重定向操作(>)中,把一個檔案長度截斷為0(:>>這樣用的時候,目標存在則什麼都不做),這個只能在普通文件中使用,不能在管道,符號鏈接和其他特殊文件中使用;5. 甚至你可以用來註釋(#後的內容不會被檢查,但:後的內容會被檢查,如果有語句如果出現語法錯誤,則會報錯);6. 你也可以作為域分隔符,比如環境變量$PATH中,或者在passwd中,都有冒號的作為域分隔符號的存在;7. 你也可以將冒號作為函數名,不過這個會將冒號的本來意義轉變(如果你不小心作為函數名,你可以使用unset -f : 來取消function的定義)。 !感嘆號(reverse (or negate) [bang],[exclamation mark])。 取反一個測試結果或退出狀態。 1. 表示反邏輯,例如後面的!=,這個是表示不等於;2. 表示取反,如:ls a[!0-9] #表示a後面不是緊接著一個數字的檔案;3. 在不同的環境裡面,感嘆號也可以出現在間接變數引用裡面;4. 在命令列中,可以用於歷史指令機制的調用,你可以試試!$,!#,或者!-3看看,不過要注意,這點特性不能在腳本文件裡面使用(被禁用)。 *星號(wildcard/arithmetic operator[asterisk])。 1. 作為匹配檔案名稱擴展的一個通配符,能自動匹配給定目錄下的每一個檔案;2. 正規表示式中可以作為字元限定符,表示其前面的符合規則符合任意次;3. 算術運算中表示乘法。 **雙星號(double asterisk)。算術運算中表示求冪運算。 ?問號(test operator/wildcard[Question mark])。
1. 表示條件測試;
2. 在雙括號內表示C風格的三元運算子((condition?true-result:false-result));
3. 參數替換表達式中用來測試一個變數是否設定了值;
4. 作為通配符,用於匹配檔案名稱擴展特性中,用於匹配單一字元;
5. 正規表示式中,表示符合其前面規則0次或1次。
$
美元符號(Variable substitution[Dollar sign])。
1. 作為變數的前導符,用作變數替換,即引用一個變數的內容,例如:echo $PATH;
2. 在正規表示式中被定義為行末( End ofline)。
${}
參數替換(Variable substitution)。
用於在字串中表示變數。
$'...'
引用內容展開,執行單引號內的轉義內容(單引號原本是原樣引用的),這種方式會將引號內的一個或者多個[\]轉義後的八進制,十六進位值展開到ASCII或Unicode字元。
$*
$@
位置參數(Positional Parameters)。
這個在使用腳本檔案的時候,傳遞參數的時候會用到。兩者都能傳回呼叫腳本檔案的所有參數,但$*是將所有參數作為一個整體傳回(字串),而$@ 是將每個參數作為單元傳回一個參數清單。請注意,在使用的時候需要用雙引號將$*,$@括住。這兩個變數受到$IFS的影響,如果在實際應用中,要考慮其中的一些細節。
$
#表示傳遞給腳本的參數數量。
$?
此變數值在使用的時候,傳回的是最後一個指令、函數、或腳本的退出狀態碼值,如果沒有錯誤則是0,如果為非0 ,則表示在此之前的最後一次執行有錯誤。
$$
進程ID變量,這個變數保存了執行目前腳本的進程ID值。
()
圓括號(parentheses)。
1, 命令群組(Command group)。由一組圓括號括起來的指令是指令組,指令組中的指令實在子shell(subshell)中執行。因為是在子shell內運行,因此在括號外面是沒有辦法獲取括號內變量的值,但反過來,命令組內是可以獲取到外面的值,這點有點像局部變量和全局變量的關係,在實作中,如果碰到要cd到子目錄操作,並在操作完成後要返回當前目錄的時候,可以考慮使用subshell來處理;
2. 用於數組的初始化。
{x,y,z,...}
花括號擴充(Brace Expansion)。
在指令中可以用這種擴充來擴充參數列表,指令將會依照列表中的括號分隔開的模式進行比對擴充。注意的一點是,這花括號擴展中不能有空格存在,如果確實有必要空格,則必須被轉義或使用引號來引用。例:echo {a,b,c}-{\ d," e",' f'}
#{a..z}
在Bash version 3時加入了這種花括號擴展的擴展,可以使用{A..Z}表示A-Z的所有字符列表,這種方式的擴展Mitchell測試了一下,好像僅適用於A-Z,a-z,還有數字{最小..最大}的這種方式擴展。
{}
程式碼區塊(curly brackets)。
這個是匿名函數,但是又與函數不同,在程式碼區塊裡面的變數在程式碼區塊後面仍能存取。注意:花括號內側需要有空格與語句分隔。另外,在xargs -i中的話,還可以作為文本的佔位符,用以標記輸出文本的位置。
{} \;
這個{}是表示路徑名,這個不是shell內建的,現在接觸到的情況看,好像只用在find指令裡。注意後面的分號,這個是結束find指令中-exec選項的指令序列,在實際使用的時候,要轉義一下以免被shell理解錯誤。
[]
中括號(brackets)。
1. 測試的表示,Shell會測試在[]內的表達式,需要注意的是,[]是Shell內建的測試的一部分,而不是使用外部命令/usr/bin/test的連結;
2. 在陣列的脈絡中,表示陣列元素,方括號內填入陣列元素的位置就能獲得對應位置的內容,如:
1. Array[ 1]=xxx
2. echo${Array[1]};
3. 表示字元集的範圍,在正表達式中,方括號表示該位置可以匹配的字符集範圍。
[[]]
雙中括號(double brackets)。
這個結構也是測試,測試[[]]之中的表達式(Shell的關鍵字)。這個比單中括號更能防止腳本裡面的邏輯錯誤,例如:&&,||,<,>運算子能在一個[[]]裡面測試通過,但在[]卻不能通過。 [[]]裡面沒有檔案名稱擴充(filename expansion)或是字分隔符號(Word splitting),但是可以用參數擴充(Parameter expansion)和指令來取代(command substitution)。不用檔案名稱通配符和像空白這樣的分隔符號。注意,這裡面如果出現了八進制,十六進制等,shell會自動執行轉換比較。
$[...]
The word expression represents integer expansion.
Execute integer expressions inside square brackets. Example:
1. a=3
2. b=7
3. echo$[$a+$b]
4. echo$ [$a*$b]
5. ##The return is 10 and 21
(())
double parentheses.
represents integer expansion.
In the double bracket structure, all expressions can be like C language, such as: a++, b--, etc.
In the double bracket structure, all variables do not need to be prefixed with the "$" symbol.
Double brackets can perform logical operations and four arithmetic operations
The double bracket structure extends the for, while, and if condition test operations
Supports multiple expression operations, each expression Use "," to separate
>
&<
>&
>>
<
<>
Redirection.
scriptname >filename redirects the output of scriptname to the file filename, and overwrites the original file if the filename file exists;
command &>filename redirects the standard output (stdout) of command and Standard error (stderr) to the file filename;
command >&2 Redirect the standard output (stdout) of command to the standard error (stderr);
scriptname >>filename Append the output of scriptname (same as >) to the file filename, or create the file if it does not exist. One > indicates that the file will be overwritten if it exists, and created if it does not exist. Two >> indicates that it will be created if it does not exist. If it exists, it will be added to the original one.
[i]<>filename Open filename The file is used for reading or writing, and i is assigned to the file as its file descriptor (file descriptor). If the file does not exist, it will be created.
<<
Double less then marks (here-document[double less then marks]).
This is also called Here-document and is used to redirect subsequent content to the stdin of the left command. < <<< Three less than signs (here-strings). Here-string is similar to Here-document, here-strings syntax: command [args] <<<["]$word["]; $word will be expanded and used as the stdin of command. \<...\> Word boundary. This is a special delimiter used in regular expressions to mark word boundaries. For example: the will match there, another, them, etc. If you only want to match the, you can use this word boundary character, \ | Pipe. Pipes are a concept that exists in both Linux and Unix. It is a very basic and important concept. Its function is to use the output (stdout) produced by the command before the pipe (on the left) as the input (stdin) of the command after the pipe (on the right). For example: ls | wc l, you can use pipes to connect commands together. Note: The standard output of each process in a pipe will be used as the standard input of the next command. The standard output during the period cannot cross the pipe and be used as the standard input of the subsequent command, such as: cat filename | ls -al | sort. Think about the output of this? Also, the pipe runs as a child process, so the pipe cannot cause variables to change. >| Force redirection. This will force overwriting of already existing files. & Run job in background[ampersand]). If the command is followed by an & symbol, the command will run in the background. && || Logical operator. In the test structure, these two operators can be used to connect two logical values. || returns 0 (true) when one of the test conditions is true, and false if all are false; && returns true (0) when both test conditions are true, and false if any. - Minus sign, hyphen (Hyphen/minus/dash). 1. As an option, the prefix [option, prefix] is used. 2. Source or destination for stdin or stdout redirection [dash]. When tar does not have bunzip2 program patch, we can do this: bunzip2 linux-2.6.13.tar.bz2 | tar xvf - . Use the previously decompressed data as the standard input of tar (a - is used here) Note: During implementation, if the file name starts with [-], then add this as a directional operation When echoing a variable, an error may occur. At this time, a suitable prefix path should be added to the file to avoid this situation. Similarly, when echoing a variable, if the variable starts with [-], it may also occur. Unexpected results. To be on the safe side, you can use double quotes to quote scalars: var="-n" echo$var var="-n" echo$var Try to see what the output is? Also, this representation method is not built-in in Bash. To achieve this effect, you need to see whether the software you are using supports this operation; 3. Represents the previous Therefore, if you cd to another directory and want to put back the previous path, you can use cd - to achieve the purpose. In fact, the [-] here uses the environment variable $OLDPWD. Note: [-] here is different from the previous point; 4. The minus sign or negative sign is used in arithmetic operations. = Equals. 1. When assigning a value to a variable, is there any space on both sides of the equal sign? 2. Appears as a comparison operator in a comparison test. Note here that if it is in square brackets To appear as a comparison, there need to be spaces on both sides of the equal sign. + Plus. 1. Arithmetic operator, indicating addition; 2. In a regular expression, it means that the preceding matching rule matches at least once; 3. As an option marker in a command or filter, use + in some commands or built-in commands to enable certain options, and use - to disable; 4. In parameter substitution (parametersubstitution), the + prefix means Substitute value (when the variable is empty, use the value after +) % percent sign (modulo[percent sign]). 1. In arithmetic operations, this is the modulus operator, which is the remainder after division of two numbers; 2. In parameter substitution (parametersubstitution), it can be used as a pattern match. Example: to # ##Start searching from the right (think about which symbol is from the left?) ##Any content between b and 9 (inclusive) ##The first one is to find The shortest matching item ##The last one is to find the largest matching item (greedy matching?) ~ tilde (Home directory[tilde]). This is the same as the internal variable $HOME. By default, it indicates the current user's home directory (home directory). This has the same effect as ~/. If the tilde is followed by the user name, it indicates the user's home directory. ^ caret. 1. In regular expressions, as the beginning-of-line position identifier of a line; 2. In parameter substitution (Parametersubstitution), this usage has two ways One caret (${var^}), or two (${var^^}), respectively means the first letter is capitalized, and all capitals means (Bash version >=4). Blank Whitespace. White space not only refers to spaces (spaces), but also includes tabs (tabs), blank lines (blank lines), or a combination of these. It can be used as a function delimiter to separate commands or variables. A blank line will not affect the behavior of the script, so it can be used to plan the script code to increase readability. The built-in special variable $IFS can be used to target certain commands. The input parameters are split, and the default is the whitespace character. If there are whitespace characters in a string or variable, you can use quotes to avoid possible errors. 以上是總結bash常用特殊字符的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

適用於 Linux 的 Windows 子系統第一種選擇是使用適用於 Linux 或 WSL 的 Windows 子系統,這是一個相容層,用於在 Windows 系統上本機執行 Linux 二進位執行檔。它適用於大多數場景,允許您在 Windows 11/10 中執行 shell 腳本。 WSL 不會自動可用,因此您必須透過 Windows 裝置的開發人員設定來啟用它。您可以透過前往設定 > 更新和安全性 > 對於開發人員來完成。切換到開發人員模式並透過選擇是確認提示。接下來,找 W

使用Java的Character.isDigit()函數判斷字元是否為數字字元在電腦內部以ASCII碼的形式表示,每個字元都有一個對應的ASCII碼。其中,數字字元0到9分別對應的ASCII碼值為48到57。要判斷一個字元是否為數字,可以使用Java中的Character類別提供的isDigit()方法來判斷。 isDigit()方法是Character類別的

如何使用自動更正在 Word 中鍵入箭頭在 Word 中鍵入箭頭的最快方法之一是使用預先定義的自動修正捷徑。如果您鍵入特定的字元序列,Word 會自動將這些字元轉換為箭頭符號。您可以使用此方法繪製多種不同的箭頭樣式。若要使用自動更正在 Word 中鍵入箭頭:將遊標移到文件中要顯示箭頭的位置。鍵入以下字元組合之一:如果您不希望將您鍵入的內容更正為箭頭符號,請按鍵盤上的退格鍵會將

您的實體或數位鍵盤在表面上提供有限數量的字元選項。但是,有幾種方法可以在iPhone、iPad和Mac上存取重音字母、特殊字元等。標準iOS鍵盤可讓您快速存取大寫和小寫字母、標準數字、標點符號和字元。當然,還有很多其他角色。您可以從帶有變音符號的字母到倒置的問號中進行選擇。您可能無意中發現了隱藏的特殊字元。如果沒有,以下是在iPhone、iPad和Mac上存取它們的方法。如何在iPhone和iPad上存取擴充字元在iPhone或iPad上取得擴充字元非常簡單。在「訊息」、「

在matplotlib中正確地顯示中文字符,是許多中文使用者常常遇到的問題。預設情況下,matplotlib使用的是英文字體,無法正確顯示中文字元。為了解決這個問題,我們需要設定正確的中文字體,並將其應用到matplotlib中。以下是一些具體的程式碼範例,幫助你正確地在matplotlib中顯示中文字元。首先,我們需要導入需要的函式庫:importmatplot

上標是一個字符或多個字符,可以是字母或數字,您需要將其設置為略高於正常文本行。例如,如果您需要寫1st,則字母st需要略高於字元1。同樣,下標是一組字符或單個字符,需要設置為略低於正常文本級別。例如,當你寫化學式時,你需要把數字放在正常字元行的下方。以下螢幕截圖顯示了上標和下標格式的一些範例。儘管這似乎是一項艱鉅的任務,但實際上將上標和下標格式應用於您的文字非常簡單。在本文中,我們將透過一些簡單的步驟說明如何輕鬆地使用上標或下標格式設定文字。希望你喜歡閱讀這篇文章。如何在 Excel 中套用上標

今年初,當Microsoft和Canonical發布Windows10Bash和Ubuntu用戶空間,我嘗試做了一些初步性能測試UbuntuonWindows10對比原生Ubuntu,這次我發布更多的,關於原生純淨的Ubuntu和基於Windows10的基準對比。 Windows的Linux子系統測試完成了所有測試,並隨著Windows10週年更新釋放。預設的Ubuntu用戶空間還是Ubuntu14.04,但已經可以升級到16.04。所以測試先在14.04測試,完成後將系統升級升級到16.04

這裡我們將看到如何使用bash腳本獲得數字A的B次方。邏輯很簡單。我們必須使用“**”運算子或冪運算子來執行此操作。讓我們看下面的程式來清楚地理解這個概念。範例#!/bin/bash#GNUbashScripta=5b=6echo"$(($a**$b))"輸出15625
