my script doesn't work :(

i have this script and when i ejecute it, the console tell me this " sintax error line 41 unexpected element "}" "

is the sintaxis ok?

#!/bin/bash

if [ $1 = '' ];then
{
    exit 0;
    }



if [ $1 = '-s' ]; then 
{
    
sudo /etc/init.d/apache2 start;
sudo /etc/init.d/mysql start;
php5 &
nautilus /var/www;

}
else
{
    
    if [ $1 = '-r' ]; then
    
    {
        sudo /etc/init.d/apache2 start;
        sudo /etc/init.d/mysql start;
        sudo killall php5;
        sudo php5 &
    }
    
    else
    
    {
        if [ $1 = '-s' ]; then
        
        
        sudo /etc/init.d/apache2 stop;
        sudo /etc/init.d/mysql stop;
        sudo killall php5;

}

}



echo 'Desea iniciar un nautilus en www?';
read rta;

if [ rta = 'si' ]; then
{
    nautilus /var/www ;
}

thanks

Remove all { and }. They're completely unnecessary here.

The closing word for an if in bash is fi

if ....; then
  ...
fi

You've also missed some $ signs ( if [ rta = 'si' ]; then ), and should generally quote variables ( if [ "$rta" = 'si' ]; then )

1 Like
#!/bin/bash

if [ $1 = '' ] ;then
    exit 0;
fi

if [ $1 = '-s' ] ; then
    sudo /etc/init.d/apache2 start;
    sudo /etc/init.d/mysql start;
    php5 &
    nautilus /var/www;
else
    if [ $1 = '-r' ] ; then
        sudo /etc/init.d/apache2 start;
        sudo /etc/init.d/mysql start;
        sudo killall php5;
        sudo php5 &
    else
        if [ $1 = '-s' ] ; then
            sudo /etc/init.d/apache2 stop;
            sudo /etc/init.d/mysql stop;
            sudo killall php5;
        fi
    fi
fi

echo 'Desea iniciar un nautilus en www?';
read rta;

if [ $rta = 'si' ] ; then
    nautilus /var/www ;
fi
1 Like

thanks it works perfectly !