使脚本能够直接运行的脚本...

背景

每次运行脚本时最难受的就是./运行权限不足,还得手动chmod,于是就写了个脚本全自动chmod.

虽然知道这个问题肯定有其他更好的方法但是依旧发上来留个念…

正文

#!/bin/bash

goin(){
cd $1
echo "============ going into $1 ============"
ls > tmp.txt
for i in `cat tmp.txt`;do
    if [ -d $i ];then
        goin $i

    elif [ ${i#*.} = 'sh' ];then
        echo "> chmod on $i"
        chmod 777 $i || exit -1

    elif [ ${i#*.} = 'py' ];then
        echo "> chmod on $i"
        chmod 777 $i || exit -1
    #追加elif从句以改变其他类型脚本执行权限
    fi
done
rm tmp.txt
echo "============ leaving $1 ============" 
cd ..
}

goin ./

说明

脚本不需要参数,放到想要chmod的文件夹内,本脚本会递归地改变当前目录下脚本的权限.

猜你喜欢

转载自blog.csdn.net/qq_37613882/article/details/78883487