How to Write a Script to Start Programs
Linux and Unix users can use the bash shell to create a script that will open one or more programs. Once created, the script can be executed from the command line or through a desktop launcher. It can also be placed in the "rc.local" file to be executed when the computer starts up. The bash shell does not have to be the default shell to use this script.
Instructions
-
-
1
Open a text editor.
-
2
Type the line "#!/bin/bash" to start the bash script.
-
-
3
Type the commands to start your programs. Each command should be on a separate line and the line should end with "&". For example, if you want to start Mozilla Firefox, Evolution, and the Pidgin Instant Messenger, your script would look like:
#!/bin/bash
firefox &
evolution &
pidgin & -
4
Save the file with the ".sh" file extension.
-
5
Open a terminal window.
-
6
Type the command "cd <directory>" to change to the directory where you saved your script. For example, type "cd scripts" if you placed the file in a directory named "scripts."
-
7
Type the command "chmod +x <script_name>.sh" to make the script executable. Replace "<script_name>" with the name of your script.
-
8
Type the command "./<script_name>.sh" to test the script. Again, replace "<script_name>" with the name of your script.
-
1
Tips & Warnings
If your script does not start the programs, use the complete path to the executable. For example, instead of "firefox &", type "/usr/bin/firefox &".