bash Script Variable Assignment Problem

Status
You're currently viewing only 2 Donuts's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

2 Donuts

Ars Tribunus Militum
2,872
I'm still new to bash scripting, and I'm trying to get a script to work. The other scripts to which this refers, start.sh and stop.sh, work fine, as well as my references to them. The only problem is that running a bad option or no option at all, i.e., "multiseatctl.sh asdlkfjasdflkj" instead of "multiseatctl.sh start," just keeps looping with "Please enter one of the following parameters: 'start' 'stop' 'restart'" instead of assigning a new value to the variable and moving on. Can anyone help?

Code:
#!/bin/bash
# This script starts, stops, or restarts (stops-then-starts) the multiseat, RMI
# registry, Java, and the simulation.  Ideally, the user will run it with
# "start," "stop," or "restart" as options.  If not, he will be prompted to 
# choose an option.

# Error tolerance.
while [ "$1" != "start" ] && [ "$1" != "stop" ] && [ "$1" != "restart" ]
        do
          	echo 'Please enter one of the following parameters: "start" "stop" "restart"'
                read newinput
                $1=newinput
        done
            	if [ "$1" = "start" ]; then
                        echo 'Starting the multiseat, RMI, and settings dialog box.'
                        # Call the start script.
                        /etc/X11/start.sh
                        # Add delays before providing text feedback, or it will be
                        # lost amongst other messages.
                        sleep 10
                        echo 'Ready to begin simulation.'
                elif [ "$1" = "stop" ]; then
                        echo 'Stopping RMI and multiseat.'
                        # Call the stop script.
                        /etc/X11/stop.sh
                        sleep 10
                        echo 'RMI and multiseat stopped.'
                else
                    	echo 'Restarting RMI and the multiseat.'
                        # Stop
                        /etc/X11/stop.sh
                        # Start after a ten-second delay.  Doing otherwise will try to
                        # start Java before the X servers have finished starting.
                        sleep 10
                        /etc/X11/start.sh
                        sleep 10
                        echo 'Ready to begin simulation.'
                fi
 

2 Donuts

Ars Tribunus Militum
2,872
willmo: Thanks for the lesson, and the script that works perfectly. I definitely like your indentation better, but I'm just using single tabs with nano 2.0.9. Is it more common to just use spaces instead?

ronelson: Thanks. The design lead wants this to always run from a terminal so that he can always see any possible error messages on-the-fly. Either he or one other specific person will be running it, as it's not for production software. The only reason the error correction was important was that typos will happen, and it's nice to account for them.
 
Status
You're currently viewing only 2 Donuts's posts. Click here to go back to viewing the entire thread.
Not open for further replies.