zsh-users
 help / color / mirror / code / Atom feed
* trying to create a "|| failed" function
@ 2013-03-15  1:39 TJ Luoma
  2013-03-15  1:55 ` Alex Satrapa
  0 siblings, 1 reply; 4+ messages in thread
From: TJ Luoma @ 2013-03-15  1:39 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 892 bytes --]

I'm trying to create a function which I can define in .zshenv which will
let me log when a command fails.

Here's what I end up doing most of the time:

LOG=$HOME/.foo.log

if ((! foo ))
then
 echo "$0: command 'foo' failed" | tee -a "$LOG"
 exit 1
fi



if ((! bar ))
then
 echo "$0: command 'bar' failed" | tee -a "$LOG"
 exit 1
fi


Here is what I'd like to be able to do instead

foo || failed

bar || failed

if 'failed' get called, I want the shell script (whatever called `foo` and
`bar`) to exit 1, and I want to log the name of the command that failed
(and, ideally, the name of the script that `foo` or `bar` was in when it
failed)

(These are simple examples, of course, but it gets more complicated when
`foo` or `bar` are longer commands, or part of a loop, etc.)

Is there a way to do this?

If so, I'd appreciate any hints suggestions, or examples you could give.

Thanks

TjL

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-15  5:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15  1:39 trying to create a "|| failed" function TJ Luoma
2013-03-15  1:55 ` Alex Satrapa
2013-03-15  3:19   ` TJ Luoma
2013-03-15  5:08     ` Phil Pennock

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).