create bash-shell-script

狄凯
2023-12-01

sometimes you want to create a bash script,a better way is using template.

so you can set a script like this - 

bash-script

#! /bin/bash 

works_dir=`pwd`

function scriptTemplate(){
cat >$1 <<EOF
#! /bin/bash 
#######################
#
#######################

# constants

# functions

# main 
[ -z "\${BASH_SOURCE[0]}" -o "\${BASH_SOURCE[0]}" = "\$0" ] || return

EOF

}

function createScript(){
    if [ ! -z $1 ]; then
        path=$works_dir/$1
        scriptTemplate $works_dir/$1 
        chmod +x $path
    else
        echo "what's the script name ?"
    fi
}

#main
if [ ! -z $1 ]; then 
    createScript $1
else 
    echo "what's your script name ?"
fi


 类似资料: