trap in shell programming

Cameron Simpson cs at zip.com.au
Mon Mar 7 10:09:26 UTC 2011


On 07Mar2011 16:01, xinyou yan <yxy.716 at gmail.com> wrote:
| thank you !
| 
| As you write . It works .
| I thought it was captured by shell. In fact  the error in cods.

Tiny errors like this can be hard to see.
You can find running scripts like this:

  sh -x your_script.sh ...

will show you what commands are actually being executed.
They you can see what is and is not happening, and also should reveal
what "wrong" things are happening (such as variables with wrong values).

| I am  just a student .
| Someone told me   some skills  are import . However  , I study it and
| find I can't use it right now .
| That lead careless  .
| May be we need to find interest in programming .

An interesting or useful task is important for many people, myself
included.

For learning the shell, I suggest that you try trivial but useful _to_
_you_ tasks, at the command prompt. Not everything needs to be in a
script. Anything you can put in a script you can type at the prompt,
pretty much.

So, perhaps you find youself needing to do something to several files.
Such as renaming them all to "thing.txt", when before they were called
"thing".

Laboriously you can go:

  $ mv thing1 thing1.txt
  $ mv thing2 thing2.txt
  $ mv thing3 thing3.txt

and so on. Or you can go:

  $ for f in thing*; do mv $f $f.txt; done

Learning to use the basic control structures (such as the "for" loop
above) in trivial convenient steps will get you started. Then it is
easier to pick up the more advanced stuff later, as you find the need.

In short: try to do stuff at the shell prompt. When something is tedious,
_then_ look for a way to make it easier, for just that task.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Yesterday, I was running a CNC plasma cutter that's controlled by Windows XP.
This is a machine that moves around a plasma torch that cuts thick steel
plate.  A "New Java update is available" window popped up while I was
working.  Not good. - John Nagle


More information about the users mailing list