bash 学习笔记(四) -其它

1. 使用 shift 来移动参数; 遇用在 -a -b -c,不要求用户按 -a -b -c 来输入的场合;
2.  getopts, 比 shift 还要做的多的是可以写成 -bca 来得到-a -b -c 所做的事情,就像 tar -zcvf  这样;
3. 类型的定义

Option

Meaning

-a

The variables are treated as arrays

-f

Use function names only

-F

Display function names without definitions

-i

The variables are treated as integers

-r

Makes the variables read-only

-x

Marks the variables for export via the environment


$  val1 = 12  val2 = 5
$  result1 = val*val2
$   echo   $ result1
val1*val2
$
$  declare -i val3 = 12  val4 = 5
$  declare -i result2
$  result2 = val3*val4
$   echo   $ result2
60

算术操作

Operator

Meaning

+

Plus

-

Minus

*

Multiplication

/

Division (with truncation)

%

Remainder

<<

Bit-shift left

>>

Bit-shift right

&

Bitwise and

|

Bitwise or

~

Bitwise not

!

Bitwise not

^

Bitwise exclusive or


数字的比较

Operator

Meaning

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

==

Equal to

!=

Not equal to

&&

Logical and

||

Logical or

数字比较2
Test
Comparison
-lt
Less than
-le
Less than or equal
-eq
Equal
-ge
Greater than or equal
-gt
Greater than
-ne
Not equal


# ! / bin / bash 
for   dir  in  $ {*:- . } ;   do
    
if  [ -e  $ dir  ] ;   then
        result
=$( du -s  $ dir  | cut -f  1 )
        let total
=$ result* 1024

        
echo  -n  " Total for $dir = $total bytes "

        
if  [  $ total -ge  1048576  ] ;   then
              
echo   "  ($((total/1048576)) Mb) "
        elif [ 
$ total -ge  1024  ] ;   then
              
echo   "  ($((total/1024)) Kb) "
        fi
    fi
done

4. 数组的使用
对数据的循环:
for i in "${names[@]}"; do
    echo $i
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值