Unix Commands and Concepts
Unix Commands and Concepts
2-1
Unix Commands and Concepts
This chapter explains fundamental Unix commands that are necessary for
understanding later scripts. It will be helpful if you know elementary Unix commands.
Books titled “Teach Yourself Unix” have excellent, simple, early chapters that give the
basics. Also, by surfing the web, you can find universities that have good tutorial sites.
Downloaded 04/08/14 to 186.116.1.6. Redistribution subject to SEG license or copyright; see Terms of Use at http://library.seg.org/
2.3.3 Pipe: |
We saw the pipe in Section 1.8. We mention it here because it is an advanced
concept. A pipe allows data to flow from one process to another. Below (as before),
2-2
Unix Commands and Concepts
suplane creates data, then the pipe sends the data to the imaging program, suxwigb to be
seen on the screen. In other words, data flow is through the pipe, left to right.
suplane | suxwigb
The redirect < sends data from right to left. Below, data file seis1.su is sent as input to
program suwind, a windowing program that we will use later.
suwind < seis1.su
The redirect combination below sends data file (a) to process (b); the output of (b) is
stored in file (c).
suwind < seis1.su > seis2.su
b < a > c
The first command below types the contents of file README to the screen. The
second command below redirects the result of the cat command to file info2.txt; the
contents of file README do not get to the screen. The third command below appends the
contents of file README to the bottom of file info2.txt; that is, the original contents of
file info2.txt are not overwritten.
cat README
cat README > info2.txt
cat README >> info2.txt
2-3
Unix Commands and Concepts
2-4
Unix Commands and Concepts
set -x
2-5
Unix Commands and Concepts
5 # Set messages on
6 ##set -x
7
8 # Define variable
9 signaltonoise=10
10
Downloaded 04/08/14 to 186.116.1.6. Redistribution subject to SEG license or copyright; see Terms of Use at http://library.seg.org/
2-6
Unix Commands and Concepts
file myplot.su. By the end of line 13, you have a new file of seismic data on your
computer. File myplot.su is the input data to the “case” logic that follows.
Lines 17-47 are the “case” logic.
Line 50 exits the shell.
Downloaded 04/08/14 to 186.116.1.6. Redistribution subject to SEG license or copyright; see Terms of Use at http://library.seg.org/
To run this script, it first must be created in an editor, saved under any name and
made executable. The script is then called with the name of the file, followed by the case
selection (see Table 2.2). For example, if the script file was saved under the name
myplot.sh, and then made executable with the command
chmod +x myplot.sh
the command
myplot.sh wiggle
runs the script and displays wiggle traces on the screen. In fact, there are four ways to run
this script:
Table 2.2: Possible cases and output of myplot.sh
Command Output
myplot.sh wiggle wiggle trace screen image
myplot.sh image bitmap screen image
myplot.sh pswiggle wiggle trace Postscript file – myplot1.eps
myplot.sh psimage bitmap Postscript file – myplot2.eps
The first two cases display seismic data directly on the screen. The latter two cases
save the created image as a Postscript file. When you run the script selecting one of the
Postscript cases, you must use one of the commands below to see the contents of the
Postscript files (if you have the Ghostscript program):
ghostview –bg white myplot1.eps &
ghostview -bg white myplot2.eps &
Your output should look like one of the four images in Figures 2.1 and 2.2 (below).
Option “-bg white” makes the ghostview background white. On many systems, the
default background is grey.
The echo command writes to the screen (unless the output of echo is redirected).
Lines 29 and 31 put blank lines above and below the output of line 30 to make line 30
output easier to read. The same is true for lines 36, 38, 37 and lines 42, 44, 43.
Last, notice line 41. This case option is used if you do not select or if you incorrectly
type one of the other cases. Case option “*)” is placed after all other cases and is always
selected if none of the previous cases are selected. This option is used here to print
information to the screen to remind you of the acceptable cases.
2-7
Unix Commands and Concepts
Downloaded 04/08/14 to 186.116.1.6. Redistribution subject to SEG license or copyright; see Terms of Use at http://library.seg.org/
2-8