bash shell

1.     在shell 中每個命令執行後都會返回0代表命令執行失敗,返回1代表命令執行成功,我們可以利用這個特性處理類似exception的功能判斷

 

 

逐行 遍歷 文件 內容

 

 

2.   bbtv  launch shell

#show all files in a folder, include the files in its subfolder
find ${sourceFolder} -type f -printf "%p /n" | awk -F"${sourceFolderName}/" '{print $2}' > ${files}

 

#show current folder's structure.
cd ${sourceFolder}
ls -lR | grep ./ | sed -e 's/.' | sed 's/://' > ${folders}

 

#create the source folder's structure in the backup folder
while   read   LINE;
  do
      echo   ${LINE}
      mkdir -p ${backupFolder}/${sourceFolderName}/${LINE}
  done   <   ${folders}

 

3.  遍歷目錄文件

for folder in `ls`
  do
    cd ${folder}
    echo "${folder}"
    num=`ls detail-* | wc -l`
    if [ $num -gt "0" ]
    then
    tmp=`grep 'Acct-Status-Type = Start'  detail-* | wc -l`
    tmp1=`grep 'NAS-Identifier =' detail-* | awk -F"=" '{print $2}' | sort | uniq`
    tmp2=`echo ${tmp1} | grep /"*/"`
    `echo ${tmp2}"     ,     "${tmp}   >> ${file}`
    fi
    cd ..
  done

 

4. 注意

    4.1  如果在 if 判斷條件中包含命令, 那麼要用 ``把這些命令包含起來

    4.2  每個命令執行後都會有一個返回信息,我們可以通過    echo $?    來查看這個命令是否正常執行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值