Shell编程练习

来源:互联网 发布:seo sem 编辑:程序博客网 时间:2024/05/16 23:37

题目:利用所学知识,写一个脚本,实现一下功能:将 uboot 源码中包含的 awk 命令的文件找出来,并将它们拷贝到一个叫 awks 的目录中。

 

程序一:

#!/bin/bash full_path_files=`grep 'awk' * -wr | awk 'BEGIN{FS=":"} {print $1}' | uniq` bk="awks"if [ ! -d $bk ]then       mkdir $bkfi for full_path_file in $full_path_filesdo       echo $full_path_file > files       file_name=`awk 'BEGIN{FS="/"} {print $NF}' files`        if [ -e "$bk/$file_name" ]       then              n=`ls $bk/$file_name* | wc -w`              n=$(($n + 1))              cp $full_path_file $bk/$file_name$n       else              cp $full_path_file $bk/$file_name       fidone

程序二:

#!/bin/bash full_path_files=`grep 'awk' * -wr | awk 'BEGIN{FS=":"} {print $1}' | uniq`bk="awks" if [ ! -d $bk ]then       mkdir $bkfi for full_path_file in $full_path_filesdo       if [ $full_path_file != collect_awk.sh ]       then              echo $full_path_file > files              file_name=`sed 's/\//#/g' files`              cp $full_path_file $bk/$file_name       fidone 


0 0