User Tools

Site Tools


keckcaves:shell_scripts

Shell Scripts

Shell scripts include commands that would normally go on a command line in a terminal window. They are very useful for frequently used commands. The first line includes “#!” and the name of the program that will accept the commands. This is followed by the sequence of commands. For example, here is a script to start 3DVisualizer on Dawn's laptop with the header file in the folder ~/data:

 #! /bin/bash
 cd ~/data
 3DVisualizer -class ImageStack DK_2_06.shdr

It is saved as a text file called 3dDK20. The shell script can be turned into an executable file by changing the permissions for the script file. To see the permissions, make sure you are in the directory with the script ('cd <path and directory>') and type:

 ls -l

returns: -rw-r–r–@ 1 sumner staff 68 Jun 4 14:52 3dDK20

Type:

 chmod u+x <file name>
 ls -l

returns: -rwxr–r–@ 1 sumner staff 68 Jun 4 14:52 3dDK20

To run the script, make sure you are in the directory of the script and type:

 ./<file name>

The './' means that the script to execute is in the directory your terminal is currently located in.

That's all there is to it!

keckcaves/shell_scripts.txt · Last modified: 2009/06/07 20:24 by sumner