bash shell 学习记录
生活随笔
收集整理的這篇文章主要介紹了
bash shell 学习记录
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
定義變量(中間沒有空格)
a=8使用變量
echo $a計算加法(注意空格)
a=8 b=2 c=`expr $a + $b` echo $c如果是乘法,需要將 * 轉(zhuǎn)義
c=`expr $a \* $b`循環(huán)控制語句
if [...] then... else... fi...注意:大于號,小于號等不能直接用符號
> -gt greater than < -lt less than >= -ge greater equeal <+ -le less equal = -eq equal != -ne no equal案例
a=8 b=2 if [ $a -gt $b ] then echo $a elseecho $b fifor循環(huán)
for1.sh
for2.sh
for((i=1;i<=10;i++)); doecho $i donefor3.sh
for((i=1;i<=10;i++)); doecho $i donewhile循環(huán)
x=1 while [ $x -le 10 ] doecho $xx=`expr $x + 1` done輸入輸出
echo "Please enter a: " read aecho "Please enter b: " read bc=`expr $a + $b` echo $a + $b = $c password="hello123" echo "Please enter a password: " read userPasswordif [ $password = $userPassword ] thenecho "password correct" elseecho "password wrong" fi判斷字符串是否為空
str1="hello" str2="world"#-z 即-zero 用于判斷是否空 #-n 即 -no zero 不空 if [ -z $str1 ] thenecho "str1 is null" elseecho "str1 is not null" fi數(shù)組
用bash 運(yùn)行腳本,而不是sh
來源B站:正月點燈籠
總結(jié)
以上是生活随笔為你收集整理的bash shell 学习记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。