shell程式總結

2021-04-12 16:53:21 字數 1378 閱讀 3325

·常用的shell

/bin/sh    /bin/bash    /bin/ksh    /usr/bin/ksh   /bin/tcsh

函式與過程

·函式function  function_name()

或function_name()

*************************==

·示例function showdot() 

*************************===

·呼叫函式

showdot

控制結構

·if控制結構

if [ test_command ] 

then

cmdfi

***********************************==

if [ test_command ]

then 

cmdelse

cmdfi

***********************************==

if [test_command ]

then

cmdelif [ test_command ]

then

cmdelif [ test_command ]

then

cmdelse

cmdfi

***********************************===

·for迴圈

for  loop_variable  in  argument_list

docmd

done

***********************************===

·while語句

while [ test_command ]

docmd

done

***********************************===

·until語句

until  [ test_command ]

docmd

done

***********************************===

·case語句

case   $variable  in 

match_1)

cmd;;

match_2)

cmd;;..

.*)cmd;;

esac

****************************************

break、continue從for或while迴圈中斷與繼續執行

shell指令碼程式

學習shell指令碼是需要經過大量的練習來鞏固語法的 就像我們當初學習c語言是一樣的 下面為自己在用shell編寫的指令碼程式。1.求1.100所有數的總和 程式如下 bin bash i 0sum 0 for i 100 i do let sum i done echo sum最終輸出結果為505...

Shell程式編寫

利用case 迴圈等結構,顯示命令選單,實現掛載 解除安裝 檔案拷貝 目錄顯示 檔案資訊顯示等子程式 這些功能分別使用函式和shell程式進行定義,然後呼叫 指令碼如下,有問題可以問我,有幫助的話多點贊 bin bash echo menu echo 1 mount echo 2 umount ec...

shell陣列總結

1.計算陣列長度 2.列出陣列索引 或者 3.列印陣列中所有值 或者 4.shell中遍歷陣列元素 for str in do echo str done 5.定義空陣列 uset array 普通陣列 1.初始化 第一種初始化 root jjy q data tmp data array orig...