當前位置:首頁 » 操作系統 » LinuxShell

LinuxShell

發布時間: 2022-02-05 23:40:45

『壹』 linux中的shell是什麼意思

ll程序呢? 簡單的說shell程序就是一個包含若干行
shell或者linux命令的文件.
象編寫高級語言的程序一樣,編寫一個shell程序需要一個文本編輯器.如VI等.
在文本編輯環境下,依據shell的語法規則,輸入一些shell/linux命令行,形成一個完整
的程序文件.
執行shell程序文件有三種方法
(1)#chmod +x file(在/etc/profile中,加入export PATH=$:~/yourpath,就可以在命令行下直接運行,像執行普通命令一樣)
(2)#sh file
(3)# . file
(4)#source file
在編寫shell時,第一行一定要指明系統需要那種shell解釋你的shell程序,如:#! /bin/bash,
#! /bin/csh,/bin/tcsh,還是#! /bin/pdksh .
2.shell中的變數
(1)常用系統變數
$ # :保存程序命令行參數的數目
$ ? :保存前一個命令的返回碼
$ 0 :保存程序名
$ * :以("$1 $2...")的形式保存所有輸入的命令行參數
$ @ :以("$1""$2"...)的形式保存所有輸入的命令行參數
(2)定義變數
shell語言是非類型的解釋型語言,不象用C++/JAVA語言編程時需要事先聲明變數.給一
個變數賦值,實際上就是定義了變數.
在linux支持的所有shell中,都可以用賦值符號(=)為變數賦值.
如:
abc=9 (bash/pdksh不能在等號兩側留下空格 )
set abc = 9 (tcsh/csh)
由於shell程序的變數是無類型的,所以用戶可以使用同一個變數時而存放字元時而存放
整數.
如:
name=abc (bash/pdksh)
set name = abc (tcsh)
在變數賦值之後,只需在變數前面加一個$去引用.
如:
echo $abc
(3)位置變數
當運行一個支持多個命令行參數的shell程序時,這些變數的值將分別存放在位置變數里.
其中第一個參數存放在位置變數1,第二個參數存放在位置變數2,依次類推...,shell保留
這些變數,不允許用戶以令外的方式定義他們.同別的變數,用$符號引用他們.

3.shell中引號的使用方法
shell使用引號(單引號/雙引號)和反斜線("\")用於向shell解釋器屏蔽一些特殊字元.
反引號(")對shell則有特殊意義.
如:
abc="how are you" (bash/pdksh)
set abc = "how are you" (tcsh)
這個命令行把三個單片語成的字元串how are you作為一個整體賦值給變數abc.
abc1='@LOGNAME,how are you!' (bash/pdksh)
set abc1='$LOGNAME,how are you!' (tcsh)
abc2="$LOGNAME,how are you!" (bash/pdksh)
set abc2="$LOGNAME,how are you!" (tcsh)
LOGNAME變數是保存當前用戶名的shell變數,假設他的當前值是:wang.執行完兩條命令後,
abc1的內容是:$LOGNAME, how are you!.而abc2的內容是;wang, how are you!.
象單引號一樣,反斜線也能屏蔽所有特殊字元.但是他一次只能屏蔽一個字元.而不能屏蔽
一組字元.
反引號的功能不同於以上的三種符號.他不具有屏蔽特殊字元的功能.但是可以通過他將
一個命令的運行結果傳遞給另外一個命令.
如:
contents=`ls` (bash/pdksh)
set contents = `ls` (tcsh)
4.shell程序中的test命令
在bash/pdksh中,命令test用於計算一個條件表達式的值.他們經常在條件語句和循環
語句中被用來判斷某些條件是否滿足.
test命令的語法格式:
test expression
或者
[expression]

在test命令中,可以使用很多shell的內部操作符.這些操作符介紹如下:
(1)字元串操作符 用於計算字元串表達式
test命令 | 含義
-----------------------------------------
Str1 = str2 | 當str1與str2相同時,返回True
Str1! = str2| 當str1與str2不同時,返回True
Str | 當str不是空字元時,返回True
-n str | 當str的長度大於0時,返回True
-z str | 當str的長度是0時,返回True
-----------------------------------------
(2)整數操作符具有和字元操作符類似的功能.只是他們的操作是針對整數
test表達式 | 含義
---------------------------------------------
Int1 -eq int2|當int1等於int2時,返回True
Int1 -ge int2|當int1大於/等於int2時,返回True
Int1 -le int2|當int1小於/等於int2時,返回True
Int1 -gt int2|當int1大於int2時,返回True
Int1 -ne int2|當int1不等於int2時,返回True
-----------------------------------------
(3)用於文件操作的操作符,他們能檢查:文件是否存在,文件類型等
test表達式 | 含義
------------------------------------------------
-d file |當file是一個目錄時,返回 True
-f file |當file是一個普通文件時,返回 True
-r file |當file是一個刻讀文件時,返回 True
-s file |當file文件長度大於0時,返回 True
-w file |當file是一個可寫文件時,返回 True
-x file |當file是一個可執行文件時,返回 True
------------------------------------------------
(4)shell的邏輯操作符用於修飾/連接包含整數,字元串,文件操作符的表達式
test表達式 | 含義
----------------------------------------------------------
! expr |當expr的值是False時,返回True
Expr1 -a expr2|當expr1,expr2值同為True時,返回True
Expr1 -o expr2|當expr1,expr2的值至少有一個為True時,返回True
-----------------------------------------------------------
注意:
tcsh shell 不使用test命令,但是tcsh中的表達式同樣能承擔相同的功能.tcsh
支持的表達式於C中的表達式相同.通常使用在if和while命令中.
tcsh表達式 | 含義
-------------------------------------------------------
Int1 <= int2 |當int1小於/等於int2時,返回True
Int1 >= int2 |當int1大於/等於int2時,返回True
Int1 < int2 |當int1小於int2時,返回True
Int1 > int2 |當int1大於int2時,返回True
Str1 == str2 |當str1與str2相同時,返回True
Str1 != str2 |當str1與str2不同時,返回True
-r file |當file是一個可讀文件時,返回True
-w file |當file是一個可寫文件時,返回True
-x file |當file是一個可執行文件時,返回True
-e file |當file存在時,返回True
-o file |當file文件的所有者是當前用戶時,返回True
-z file |當file長度為0時,返回True
-f file |當file是一個普通文件時,返回True
-d file |當file是一個目錄時,返回True
Exp1 || exp2 |當exp1和exp2的值至少一個為True時,返回True
Exp1 && exp2 |當exp1和exp2的值同為True時,返回True
! exp |當exp的值為False時,返回True

『貳』 linux下的shell是什麼

什麼是shell
shell是用戶和Linux
操作系統
之間的
介面
。Linux中有多種shell,其中預設使用的是Bash。本章講述了shell的工作原理,shell的種類,shell的一般操作及Bash的
特性

什麼是shell
Linux系統的shell作為操作系統的
外殼
,為用戶提供使用操作系統的介面。它是
命令語言
、命令
解釋程序

程序設計語言
的統稱。
shell是用戶和
Linux內核
之間的介面
程序
,如果把Linux內核想像成一個
球體
的中心,shell就是圍繞
內核
的外層。當從shell或其他程序向Linux傳遞命令時,內核會做出相應的反應。
shell是一個命令語言
解釋器
,它擁有自己內建的shell命令集,shell也能被系統中其他
應用程序
所調用。用戶在提示符下輸入的命令都由shell先解釋然後傳給Linux核心。
Shell是一種具備
特殊功能
的程序,
它是介於使用者和
UNIX/linux
操作系統之核心
程序(kernel)間的一個介面。為什麼我們說
shell
是一種介於系統核心程序與使用者
間的中介者呢?讀過操作系統概論的讀者們都知道操作系統是一個
系統資源
的管理者與分
配者,當您有需求時,您得向系統提出;從操作系統的角度來看,它也必須防止使用者因
為錯誤的操作而造成系統的傷害?眾所周知,對
計算機
下命令得透過命令(command)

是程序(program);程序有編譯器(compiler)將程序轉為
二進制代碼
,可是命令呢?
其實shell
也是一支程序,它由
輸入設備
讀取命令,再將其轉為計算機可以了解的機械碼,
然後執行它。
各種操作系統都有它自己的
shell,以
DOS
為例,它的
shell
就是
command.com文
件。如同
DOS
下有
NDOS,4DOS,DRDOS
等不同的命令解譯程序可以取代標準的
command.com
,UNIX
下除了
Bourne
shell(/bin/sh)
外還有
C
shell(/bin/csh)、
Korn
shell(/bin/ksh)、Bourne
again
shell(/bin/bash)、Tenex
C
shell(tcsh)
等其它的
shell。UNIX/linux將
shell
獨立於核心程序之外,
使得它就如同一般的應用
程序,
可以在不影響操作系統本身的情況下進行修改、更新版本或是添加新的功能。
有一些命令,比如改變工作目錄命令cd,是包含在shell
內部
的。還有一些命令,例如
拷貝
命令cp和移動命令rm,是存在於
文件系統
中某個目錄下的單獨的程序。對用戶而言,不必關心一個命令是建立在shell內部還是一個單獨的程序。
shell首先檢查命令是否是
內部命令
,若不是再檢查是否是一個應用程序(這里的應用程序可以是Linux本身的
實用程序
,如ls和rm,也可以是購買的商業程序,如xv,或者是
自由軟體
,如emacs)。然後shell在搜索
路徑
里尋找這些應用程序(搜索路徑就是一個能找到可執行程序的目錄列表)。如果鍵入的命令不是一個內部命令並且在路徑里沒有找到這個
可執行文件
,將會顯示一條錯誤信息。如果能夠成功找到命令,該內部命令或應用程序將被分解為
系統調用
並傳給Linux內核。
shell的另一個重要特性是它自身就是一個解釋型的程序設計語言,shell程序設計語言支持絕大多數在
高級語言
中能見到的程序
元素
,如
函數

變數

數組
和程序控制結構。shell
編程語言
簡單易學,任何在提示符中能鍵入的命令都能放到一個可執行的shell程序中。
當普通用戶成功登錄,系統將執行一個稱為shell的程序。正是shell進程提供了命令行提示符。作為默認值(TurboLinux系統默認的shell是BASH),對普通用戶用「$」作提示符,對超級用戶(root)用「#」作提示符。
一旦出現了shell提示符,就可以鍵入
命令名稱
及命令所需要的
參數
。shell將執行這些命令。如果一條命令花費了很長的時間來運行,或者在屏幕上產生了大量的輸出,可以從
鍵盤
上按ctrl+c發出中斷
信號
來中斷它(在正常結束之前,中止它的執行)。
當用戶准備結束登錄對話進程時,可以鍵入logout命令、exit命令或文件結束符(EOF)(按ctrl+d實現),結束登錄。

『叄』 linux下的 shell到底是什麼啊

在計算機科學中,是指「提供用戶使用界面」的軟體,通常指的是命令行界面的解析器。一般來說,shell是指操作系統中,提供訪問內核所提供之服務的程序。

『肆』 linux shell 中&>是什麼意思

& 後台執行
> 輸出到
不過聯合使用也有其他意思,比如nohup輸出重定向上的應用
例子:nohup abc.sh > nohup.log 2>&1 &
其中2>&1 指將STDERR重定向到前面標准輸出定向到的同名文件中,即&1就是nohup.log

『伍』 Linux shell #* 是什麼意思

這是 變數擴展表達式。
"#* " 是指從變數host中刪除空格前面的所有字元
一下摘取自 bash manual

${parameter#word}
${parameter##word}
The word is expanded to proce a pattern just as in filename expansion (see section 3.5.8 Filename Expansion). If the pattern matches the beginning of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the `#' case) or the longest matching pattern (the `##' case) deleted. If parameter is `@' or `*', the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with `@' or `*', the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter%word}
${parameter%%word}
The word is expanded to proce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the `%' case) or the longest matching pattern (the `%%' case) deleted. If parameter is `@' or `*', the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with `@' or `*', the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter/pattern/string}
${parameter//pattern/string}

The pattern is expanded to proce a pattern just as in filename expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. In the first form, only the first match is replaced. The second form causes all matches of pattern to be replaced with string. If patternbegins with `#', it must match at the beginning of the expanded value of parameter. If pattern begins with `%', it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omitted. If parameter is `@' or `*', the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with `@' or `*', the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.

${parameter:-word}
If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
${parameter:=word}
If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
${parameter:?word}
If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted.
${parameter:+word}
If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.
${parameter:offset}
${parameter:offset:length}
Expands to up to length characters of parameter starting at the character specified by offset. If length is omitted, expands to the substring of parameter starting at the character specified by offset. length and offset are arithmetic expressions (see section 6.5 Shell Arithmetic). This is referred to as Substring Expansion.

length must evaluate to a number greater than or equal to zero. If offset evaluates to a number less than zero, the value is used as an offset from the end of the value of parameter. If parameter is `@', the result is length positional parameters beginning at offset. If parameter is an array name indexed by `@' or`*', the result is the length members of the array beginning with ${parameter[offset]}. Substring indexing is zero-based unless the positional parameters are used, in which case the indexing starts at 1.
${!prefix*}
Expands to the names of variables whose names begin with prefix, separated by the first character of the IFS special variable.
${#parameter}
The length in characters of the expanded value of parameter is substituted. If parameter is `*' or `@', the value substituted is the number of positional parameters. If parameter is an array name subscripted by `*' or `@', the value substituted is the number of elements in the array.

『陸』 Linux shell 腳本中, $@ 和$# 分別是什麼意思

直接看示例:
[root@localhost xly]# cat t.sh
#!/bin/bash
echo $#
echo $@
[root@localhost xly]# sh t.sh
0
[root@localhost xly]# sh t.sh a b c
3
a b c
說明:
$@表示所有參數
$#表示所有參數的個數

『柒』 linux中的shell究竟是什麼

【一】
shell的含義:
首先shell的英文含義是「殼」;
它是相對於內核來說的,因為它是建議在核的基礎上,面向於用戶的一種表現形式,比如我們看到一個球,見到的是它的殼,而非核。
Linux中的shell,是指一個面向用戶的命令介面,表現形式就是一個可以由用戶錄入的界面,這個界面也可以反饋運行信息;
【二】shell在Linux中的存在形式:
由於Linux不同於Windows,Linux是內核與界面分離的,它可以脫離圖形界面而單獨運行,同樣也可以在內核的基礎上運行圖形化的桌面。
這樣,在Linux系統中,就出現了兩種shell表現形式,一種是在無圖形界面下的終端運行環境下的shell,另一種是桌面上運行的類型Windows
的MS-DOS運行窗口,前者我們一般習慣性地簡稱為終端,後者一般直接稱為shell
【三】shell如何執行用戶的指令
shell有兩種執行指令的方式,一種方法是用戶事先編寫一個sh腳本文件,內含shell腳本,而後使用shell程序執行該腳本,這種方式,我們習慣稱為shell編程。
第二種形式,則是用戶直接在shell界面上執行shell命令,由於shell界面的關系,大家都習慣一行行的書寫,很少寫出成套的程序來一起執行,所以也稱命令行。
總結:shell可以說只是為用戶與機器之間搭建成的一個橋梁,讓我們能夠通過shell來對計算機進行操作和交互,從而達到讓計算機為我們服務的目的。
以上。
參考資料:
【shell的定義】http://ke..com/view/849.htm
【shell學習】http://wiki.ubuntu.org.cn/Shell%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80

『捌』 linux shell中'""和`的區別

和現在的開發語言一樣,語法上有些差異!

三種主要的 Shell 與其分身

在大部份的UNIX系統,三種著名且廣被支持的shell 是Bourne shell(AT&T shell,在 Linux 下是BASH)、C shell(Berkeley shell,在 Linux 下是TCSH)和 Korn shell(Bourne shell的超集)。這三種 shell 在交談(interactive)模式下的表現相當類似,但作為命令文件語言時,在語法和執行效率上就有些不同了。

Bourne shell 是標準的 UNIX shell,以前常被用來做為管理系統之用。大部份的系統管理命令文件,例如 rc start、stop 與shutdown 都是Bourne shell 的命令檔,且在單一使用者模式(single user mode)下以 root 簽入時它常被系統管理者使用。Bourne shell 是由 AT&T 發展的,以簡潔、快速著名。 Bourne shell 提示符號的默認值是 $。

C shell 是柏克萊大學(Berkeley)所開發的,且加入了一些新特性,如命令列歷程(history)、別名(alias)、內建算術、檔名完成(filename completion)、和工作控制(job control)。對於常在交談模式下執行 shell 的使用者而言,他們較喜愛使用 C shell;但對於系統管理者而言,則較偏好以 Bourne shell 來做命令檔,因為 Bourne shell 命令檔比 C shell 命令檔來的簡單及快速。C shell 提示符號的默認值是 %。

Korn shell 是Bourne shell 的超集(superset),由 AT&T 的 David Korn 所開發。它增加了一些特色,比 C shell 更為先進。Korn shell 的特色包括了可編輯的歷程、別名、函式、正規表達式萬用字元(regular expression wildcard)、內建算術、工作控制(job control)、共作處理(coprocessing)、和特殊的除錯功能。Bourne shell 幾乎和 Korn shell 完全向上兼容(upward compatible),所以在 Bourne shell 下開發的程序仍能在 Korn shell 上執行。Korn shell 提示符號的默認值也是 $。在 Linux 系統使用的 Korn shell 叫做 pdksh,它是指 Public Domain Korn Shell。

除了執行效率稍差外,Korn shell 在許多方面都比 Bourne shell 為佳;但是,若將 Korn shell 與 C shell 相比就很困難,因為二者在許多方面都各有所長,就效率和容易使用上看,Korn shell 是優於 C shell,相信許多使用者對於 C Shell 的執行效率都有負面的印象。

在shell 的語法方面,Korn shell 是比較接近一般程序語言,而且它具有子程序的功能及提供較多的資料型態。至於 Bourne shell,它所擁有的資料型態是三種 shell 中最少的,僅提供字元串變數和布爾型態。在整體考量下 Korn shell 是三者中表現最佳者,其次為 C shell,最後才是 Bourne shell,但是在實際使用中仍有其它應列入考慮的因素,如速度是最重要的選擇時,很可能應該採用 Bourne shell,因它是最基本的 shell,執行的速度最快。
作者: benny_feng 發布日期: 2006-10-17
tcsh 是近幾年崛起的一個軟體(Linux 下的C shell 其實就是使用 tcsh)執行,它雖然不是UNIX 的標准配備,但是從許多地方您都可以下載到它。如果您是 C shell 的擁護者,筆者建議不妨試試 tcsh,因為您至少可以將它當作是 C shell 來使用。如果您願意花點時間學習,您還可以享受許多它新增的優越功能,例如:

1. tcsh 提供了一個命令列(command line)編輯程序。

2. 提供了命令列補全功能。

3. 提供了拼字更正功能。它能夠自動檢測並且更正在命令列拼錯的命令或是單字。

4. 危險命令偵測並提醒的功能,避免您一個不小心執行了rm* 這種殺傷力極大的命令。

5. 提供常用命令的快捷方式(shortcut)。

bash 對 Bourne shell 是向下兼容(backward compatible),並融入許多C shell 與Korn shell 的功能。這些功能其實 C shell(當然也包括了tcsh)都有,只是過去 Bourne shell 都未支持。以下筆者將介紹 bash 六點重要的改進(詳細的使用說明筆者會在以後的章節介紹):

1. 工作控制(job contorl)。bash 支持了關於工作的訊號與指令,本章稍後會提及。

2. 別名功能(aliases)。alias 命令是用來為一個命令建立另一個名稱,它的運作就像一個宏,展開成為它所代表的命令。別名並不會替代掉命令的名稱,它只是賦予那個命令另一個名字。

3. 命令歷程(command history)。BASH shell 加入了C shell 所提供的命令歷程功能,它以 history 工具程序記錄了最近您執行過的命令。命令是由 1 開始編號,默認值為500。history 工具程序是一種短期記憶,記錄您最近所執行的命令。要看看這些命令,您可以在命令列鍵入 history,如此將會顯示最近執行過之命令的清單,並在前方加上編號。

這些命令在技術上每個都稱為一個事件。事件描述的是一個已經採取的行動(已經被執行的命令)。事件是依照執行的順序而編號,越近的事件其編號碼越大,這些事件都是以它的編號或命令的開頭字元來辨認的。history 工具程序讓您參照一個先前發生過的事件,將它放在命令列上並允許您執行它。最簡單的方法是用上下鍵一次放一個歷程事件在您的命令列上;您並不需要先用 history 顯示清單。按一次向上鍵會將最後一個歷程事件放在您的命令列上,再按一次會放入下一個歷程事件。按向下鍵則會將前一個事件放在命令列上。

『玖』 linux中的shell是什麼有什麼作用

Shell是人機交互用的一個程序。
用戶有shell了就可以登陸系統並且可以用命令和系統交互,肯定不安全。
沒有shell就無法用命令去和系統對話,自然安全多了。
最「土」的辦法就是用用戶名和密碼登陸一下,能進去就是有用戶shell,進不去就是沒有用戶shell。

熱點內容
linux下ntp伺服器搭建 發布:2024-09-08 08:26:46 瀏覽:742
db2新建資料庫 發布:2024-09-08 08:10:19 瀏覽:171
頻率計源碼 發布:2024-09-08 07:40:26 瀏覽:778
奧迪a6哪個配置帶後排加熱 發布:2024-09-08 07:06:32 瀏覽:101
linux修改apache埠 發布:2024-09-08 07:05:49 瀏覽:209
有多少個不同的密碼子 發布:2024-09-08 07:00:46 瀏覽:566
linux搭建mysql伺服器配置 發布:2024-09-08 06:50:02 瀏覽:995
加上www不能訪問 發布:2024-09-08 06:39:52 瀏覽:811
銀行支付密碼器怎麼用 發布:2024-09-08 06:39:52 瀏覽:513
蘋果手機清理瀏覽器緩存怎麼清理緩存 發布:2024-09-08 06:31:32 瀏覽:554