Linux脚本——let整型变量赋值及计算

#!/bin/bash

function directory()
{
    let "filenum = 0"
    let "dirnum = 0"

    ls $1
    echo ""

    for file in $( ls )
    do
        if [ -d $file ]
        then
            let "dirnum = dirnum + 1"
        else
            let "filenum = filenum + 1"
        fi    
    done

    echo "The number of directories is $dirnum"
    echo "The number of files is $filenum"
}

# 调用函数
directory

 

posted on 2024-05-07 23:29  gkhost  阅读(13)  评论(0编辑  收藏  举报

导航