我有一些问题。 我需要添加在Linux的自动运行,一些脚本。 但是在我的基础设施上,我有一个不同的分歧。 当然,在autorun中添加这个脚本的方式是不同的。 在CentOS中是chkconfig,在debian / ubuntu中是update-rc.d。 所以,我有一些脚本:
function autorun () { if [ -f /etc/debian_version ]; then os="Debian $(cat /etc/debian_version)" echo $os update-rc.d ${i} defaults" elif [ -f /etc/redhat-release ]; then os=`cat /etc/redhat-release` echo $os chkconfig --add ${i}" else os="$(uname -s) $(uname -r)" echo $os echo "Other OS. Please check type of autorun in your OS" fi } $i=nginx autorun $i
是的,这是有效的。 我可以写这个没有variables声明,像这样:
autorun nginx
请帮忙,可能是你可以提出其他的方式,那会好的。 谢谢。
在bash ,函数的参数在variables$1 , $2等中可用,
function ar () { echo $1 }
会导致
> ar Hello Hello > ar Hello World Hello > ar "Hello World" Hello World
我相信这就是你所追求的,但是,如果不是的话,编辑你的问题,使之更加清晰。