script-detector.sh
#!/bin/bash
#check all shell scripts in a directory.
testchars=2
shabang='#!'
for file in *
do
if [[ $(head -c$testchars "$file") = "$shabang" ]];then
echo "File \"$file\" is a script."
else
echo "File \"$file\" is not a script."
fi
done
exit 0
验证:
[root@kibana ztj]# sh script-detector.sh
File "data-file" is not a script.
File "include.sh" is a script.
File "script-detector.sh" is a script.
[root@kibana ztj]#