以传参的方式执行shell(模板)
Posted small-wei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了以传参的方式执行shell(模板)相关的知识,希望对你有一定的参考价值。
以传参的方式执行shell(模板)
#!bin/bash # USE: Template # author : xiaowei # date: 2019-11-01 # state : -name 选项必选,,, -v -m 选项可选; -v 设置有默认参数 # Version : beta 1.0.1 2019-11-01 function f_syntax { [ ! -z "$1" ] && echo ">>[$(date +"%Y%m%d.%H%M%S")] $1" echo " " echo "syntax:" echo "sh ${ShellName} <-name ‘Parameter 1 |Parameter 1‘> [-m test] [-v v1.0.1]" echo " " } unset MALLCHECK;export LC_ALL=C;export LANG=en_US;export TZ="BEIST-8"; ShellName="$(echo $0 | awk -F / ‘{print $NF}‘)";ShllOption=‘$@‘; ShellPID=$$;PShellName=$(echo "${ShellName}" | sed ‘s/^[0-9]*_//‘); WorkDir="$(echo $0 | sed s/${ShellName}//g)";[ -z "${WorkDir}" ] && WorkDir=${PWD};cd ${WorkDir};WorkDir=${PWD}; LogDir="${WorkDir/logs}";mkdir -p ${LogDir};chmod ugo+rwx ${LogDir} 2>/dev/null; LogFile="${LogDir}/${ShellName}.$(date +"%Y%m%d").log"; touch "${LogFile}" 2>/dev/null;chmod ugo+rw "${LogFile}" 2>/dev/null; typeset Shellcksum=$(cksum ${WorkDir%/}/${ShellName} 2>/dev/null | awk ‘{printf "%d",$1}‘); uname_n=$(uname -n);typeset uname_a=$(uname -a);typeset Platform$(echo ${uname_a%% *} | tr a-z A-Z); typeset -i UserID=${UserID:-$(id -u)};typeset UserName=${UserName:-$(whoami)}; typeset UserHome=${UserHome:-$(awk -F: -v nu="${UserName}" ‘{if($1==nu){print $6;exit}}‘ /etc/passwd 2 >/dev/null)}; [[ $# -eq 0 ]] && f_syntax; for inopt in ${ShllOption} do case $(echo $inopt | tr a-z A-Z) in -NAME) CurOpt="-NAME";typeset In_Version="v1.0.1";continue;; -VERSION|-V) CurOpt="-VERSION";continue;; -M) CurOpt="-DESCRIBE";continue;; -*) f_syntax;; esac case #-NAME) typeset In_Name="${inopt}";continue;; -NAME) typeset In_Names="${inopt}";In_Name_s=$(echo ${In_Name} ${In_Names});In_Name=${In_Name_s};continue;; -VERSION) typeset In_Version="${inopt}";continue;; -DESCRIBE) typeset In_M="${inopt}";continue;; esac done [[ -z ${inopt} ]] && echo "-name Parameter does not exist" && f_syntax;
以上是关于以传参的方式执行shell(模板)的主要内容,如果未能解决你的问题,请参考以下文章
Linux Shell 通过传参的方式往/etc/user.conf里添加用户