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

 


程序一:

 

#!/bin/bash

full_path_files=`grep 'awk' * -wr | awk 'BEGIN{FS=":"} {print $1}' | uniq`

bk="awks"
if [ ! -d $bk ]
then
mkdir $bk
fi

for full_path_file in $full_path_files
do
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
fi
done

程序二:

#!/bin/bash

full_path_files=`grep 'awk' * -wr | awk 'BEGIN{FS=":"} {print $1}' | uniq`
bk="awks"

if [ ! -d $bk ]
then
mkdir $bk
fi

for full_path_file in $full_path_files
do
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
fi
done