Linux命令文檔

在輸入和輸出之間數據的流向稱爲數據流

數據流

  • 變量
  • 計算邏輯
  • 控制循環
  • 輸入輸出

變量

本地變量 name=xxx
局部變量 local–函數中的變量
環境變量 帶有export
特殊變量 獲取當的pid $ $ 取當前參數個數 $ # 獲取第*個參數的位置 $ * 獲取全部參數$ @ 輸出上一條指令的執行狀態 $ ? 獲取當前進程的實際pid $ BASHPID
位置變量 與$*相似 超過9的位置用{}括住 栗子: $ {12} 第12個位置的參數

計算邏輯

  1. let
    $ (())((算術表達式))
    栗子:c=$$(( $ A+$ B)) c爲A+B的結果
    expr 算術表達式
    注意: 表達式中個操作數及運算符之間要有空格,而且要使用命令引用 等號左右不能有空格
    栗子:c=expr $a + $b //等號後用反單引號括住
  1. test
    條件表達式
    [ expression ] //expression:條件
    栗子:test [ epression ]
    [[ expression ]]
    栗子:[[] expression ]
    備註expression: -eq,-ne,-lt,-le,-gt,-ge

如果有不瞭解的地方可以採用linux自帶的help命令~~~

控制循環

for		while		do-while		switch-case		if
//linux循環中也可以使用break和continue~~
for:
1. for name in 1 2 3 4 5
	do
		commands
	done
	
2. for((i=1;i<=5;i++))
	do
		commands
	done
	
3. for循環的嵌套

5. for name in `seq n`----打印1到n個數字的隊列
	do
		commands
	done
	
5.無限循環:for ((;;))
				do
					commands
				done
while:
1. while commands
	do
		commands
	done
	
2. 無限循環: while :
				do
					commands
				done
switch-case:
 case $num in
		1) ;;
		2) ;;
		3) ;;
		...
		*) ;;
esac
if:
1. if commands
	then
		commands
	fi
	
2. if commands
	then
		commands
	elif commands
		commands
	fi
	
3. if commands
	then
		commands
	elif commands
	then
		commands
	else
		commands
	fi

輸入輸出

輸 入 : 0
標準輸出:1
錯誤輸出:2

>爲輸出的標誌
<爲輸入的標誌

echo “aa” 1>test.txt
將原本輸出在控制檯的 “aa” 打印到了test文本中,覆蓋test.txt中的內容
cat a.txt b.txt 1>test.txt 2>test.txt
同時將2個信息打印到test.txt ,此時,前面的會覆蓋後面的,所以在test中只顯示第一個信息
cat a.txt b.txt 1>test.txt 2>>1
同時將2個信息打印到test.txt,且將後面的信息追加到前面中,一起覆蓋到test.txt文件中

read a<<<“aaaaa”
即 變量a的值爲"aaaaa"

read a<<“aa”
會顯示輸入界面 知道按下Ctrl+c或者輸入aa結束,但是a的值爲第一次換行前輸入的值

read a
會顯示輸入界面 輸入按下回車,a的值爲輸入的值


僅供參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章