得到所有目录与对目录下的文件进行操作的shell脚本

#! /bin/sh

[ $# -ne 1 ] &&
{
        echo "usage: ./${0##*/} <path>"
        exit 0
}



function notcompile ()
{
	ifelf=0
	#echo $1
	filesinsub=$(ls)
	#echo $filesinsub
	for eachfile in $filesinsub
	do
		if [ $ifelf -eq 1 ]
		then
			#echo "elf file exist"
			break
		fi
		

		elffileexist=$(file $eachfile | grep [Ee][lL][fF])
		[ -n "$elffileexist" ] &&  ##if it is elf file, then run belows
		{
			#echo $(file $eachfile) 
			ifelf=1
		}
		
	done

	if [ $ifelf -eq 0 ] ##有.c文件的但是没有elf文件的
	then

		#echo $1 ##已经可以输出了 
		#echo $(ls)
		#echo " "
		#echo " "
		#echo " "
		{
		ismakefiles=$(ls)
		for ismakefile in $ismakefiles
		do
		if [ "${ismakefile}" = "Makefile" ]
		then
			echo $1
			echo $(ls)
	                echo " "
        	        echo " "
                	echo " "
			break
		fi
		done
		}
	fi
	if [ $ifelf -eq 1 ]
	then
		ifelf=0
	fi
}



dirs=$(find $1 | sort)
direxsit=0
for dir in $dirs
do 
	if [ -d $dir ]
	then
	{
		cd $dir
		files=$(ls)  

		for file in $files
		do
			if [ $direxsit -eq 1 ]
			then
				direxsit=0
				break
			fi
			
			if [ "${file#*.}" = "c" ]
			then	
			#filemeta_c=$(file $file | grep "ASCII C program text")
			#if [ -n "$filemeta_c" ] ##c file exist
			#then
				direxsit=1
				notcompile $dir
				#break
			fi
		done
		
		cd - > /dev/null
	}
	fi	
done

你可能感兴趣的:(shell,function,File,脚本,Path,makefile)