UNIX Intro and Basic C Shell Scripting: Khaldoun Makhoul Khaldoun@nmr - Mgh.harvard - Edu
UNIX Intro and Basic C Shell Scripting: Khaldoun Makhoul Khaldoun@nmr - Mgh.harvard - Edu
C shell Scripting
Khaldoun Makhoul
[email protected]
December 2nd 2010 Why.N.How
1
This talk introduces the audience to the basic use of the UNIX/Linux command line tools and to basic C shell
scripting.
Text
2010/12/02 Why.N.How
Why the command line?
>
?
Old-school Command
Line Interface
Touch
Mouse
???
2
First, some words of motivation:
In a time of increasingly advanced and often *usefully* simplied interfaces, why use something as old and
seemingly retrograde as the command line?
The fact remains that when it comes to power, exibility, speed and automation (scriptability), the command
line is still the best human-computer interface we have. Its old-school look and feel belies a truly powerful set
of tools for doing scientic computing.
The main disadvantage of this interface is its still-steep learning curve. This talk is here to soften that slope
and to enable you to begin learning on your own by introducing a few basic concepts and examples.
Rigor is secondary here: command line, unix shell, terminal, etc. All these words technically refer to disparate
concepts that you may in time wish to distinguish from one another. But for the purposes of this talk, if you are
entering text commands at a text-only prompt, that is all you need to worry about.
(For the curious, we will focus on the tcsh shell, and I am demonstrating this in the Mac OS X Terminal
program.)
Text
2010/12/02 Why.N.How
Power
Flexibility
Speed
Scriptability
3
Old-school Command
Line Interface
Why the command line?
Text
2010/12/02 Why.N.How
1. Intro making rm (to delete les) safer
2. Grab-bag of basic commands & info
3. Command options. grep and find
4. A sample backup script
5. Output redirection & pipes
6. Input parameters
7. Looping
8. Conditional statements
4
Outline
This talk will proceed by practical example. I will
expand on relevant concepts as they come up.
Intro to Linux & command line
Intro to scripting
Unix/Linux/GNU and all related topics can be dry enough as it is. This is why this talk essentially skips general
expository material as much as possible. We!ll dive in by example right away. The general concepts of how
the command line works will be discussed when they come up.
As such, this talk is organized informally by what I deemed useful for a rst-time or near-rst-time user. The
basic idea is to get you comfortable moving around the command line and to get you writing scripts asap.
The ne details, you!ll pick up along the way.
Text
2010/12/02 Why.N.How 5
Part I
Intro to Linux &
command line
Commands/programs/les introduced:
ls (list les)
rm (delete les)
command
command options
command arguments
Its useful to save them when running scripts so that you can
examine if anything went wrong
! logical negation
|| logical OR
== equals
!= not equals
File operators
More at www.csem.duke.edu/Cluster/csh_basics.htm
or at man csh (File inquiry operators)
Text
2010/12/02 Why.N.How 35
Conditional statements
Always look at the manual page for any command youre not
familiar with, or at the very least Google the command for
some basic info.