Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Safe scripting



On Wed, 21 Jan 2009, Thorsten Kampe wrote:

what is the best way to detect errors in a (zsh) script?

Or to be more specific: shell scripts (in contrast to other scripting
languages) keep on running even if an error occurs. How can I detect
errors in a script and exit if one occurs?
====================

TRAPZERR () {
	print "something went wrong" >&2
	exit 1
}

more info in the zshmisc man page.

or...

cd foo && \
    rm bar && \
    cd foobar && \
    rm foobarbar




Say, I have a sequence of commands that all depend on each other:

cd foo
rm bar
cd foobar
rm foobarbar

I could query each commands return code like
if cd foo;
   then if rm bar;
            then if cd foobar;
                     then rm foobarbar; fi; fi; fi

But of course that looks to weird. So what would you suggest?!

Thorsten




--
        ...atom

 ________________________
 http://atom.smasher.org/
 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
 -------------------------------------------------

	"Patriotism is your conviction that this country is superior
	 to all other countries because you were born in it."
		-- George Bernard Shaw



Messages sorted by: Reverse Date, Date, Thread, Author