Shell script to check whether a file exists in a directory

#!/bin/bash 

check_file_name()
{
    
    
	val=`ls ./*.sh | grep $1 | wc -w`
	if [ $val -eq 0 ]
	then 
		echo "do not have $1"
	else
		echo "have $1"
	fi
}

echo -n  "Input file name >>>"

read FILE

check_file_name $FILE 


Test Results

Insert picture description here

Guess you like

Origin blog.csdn.net/zxy131072/article/details/108519162