Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    commands in bash script only run after typing exit

    What i am trying to do is create a script to start and stop xampp. it seems pretty simple, but I think the sudo commands and sudo su command is screwing it up. here is the code:
    PS3='Please enter your choice: '
    options=("start" "stop" "quit")
    select opt in "${options[atsymbol]}"
        case $opt in
                echo "starting"
                sudo su
    	    sudo service apache2 stop
    	    /opt/lampp/lampp start
                echo "stopping"
                sudo su
    	    /opt/lampp/lampp stop
            *) echo invalid option;;
    ***forum wont let me type the at symbol because it thinks its a url but thats supposed to be the at symbol where i say atsymbol

    it says "starting" and "stopping" when i select an option but wont run the rest of the commands until I type exit, and then it asks me again to selecct an option.

    also when i select 2, it does the same thing except it tells me i do not have the permissions, even though i have the same sudo su command that is used in selection one.

    im hoping this is a simple problem

  2. #2
    Linux Engineer
    Join Date
    Jan 2005
    Saint Paul, MN
    Your problem is that you are starting a root shell via the "sudo su" command. This starts a new shell and when you type exit you exit from the this new "root shell" allowing the command after the "sudo su" to run as the "sudo su" command has completed. You have this case in both the "start" and "stop" cases.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    What alf55 said. In your script, remove the "sudo su" commands. They are not necessary unless /opt/lampp/lampp start/stop needs to be run as root, in which case add "sudo" at the front of those, as in : sudo /opt/lampp/lampp start
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts