case "$f" in *.* ) echo "$f already has an extension" continue ;; esac first_line="" IFS= read -r first_line < "$f" 2>/dev/null
case "$first_line" in "#!"* ) ;; * ) echo "# $f does not have a #! line" continue ;; esac ext="" case "$first_line" in *perl* ) ext="pl" ;; *sh* ) ext="sh" ;; *python* ) ext="py" ;; esac # 现在我们已经找到了#!开头且带有解释器的 # 那ext没有赋值的就是没有解释器的 if [ -z "$ext" ]; then echo "# $f no extension for #! line" continue fi # 检查改出来的文件是否已存在重名 if [ -f "$f.$ext" ]; then echo "# $f.$ext already exists" continue fi