0

i have some problem. I need to add in autorun of linux, some scripts. But in my infrastructure, i have a different distrs. Of course, the way of adding this scripts in autorun different. In CentOS it is chkconfig, in debian/ubuntu it is update-rc.d. So, i have some script:

    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 

Yes, it's works. Can i write this without variable declaration, like this:

autorun nginx

Please help, may be you can propose other way, that will be good. Thanks.

1 Answers1

1

In bash, parameters to functions are available in the variables $1, $2 etc,

function ar () 
{
    echo $1
}

would result in

> ar Hello
Hello

> ar Hello World
Hello

> ar "Hello World"
Hello World

I believe that's what you are after, but if not, edit your question to make it more clear.

Sven
  • 98,649
  • 14
  • 180
  • 226