From: TJ Luoma <luomat@gmail.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: trying to create a "|| failed" function
Date: Thu, 14 Mar 2013 21:39:11 -0400 [thread overview]
Message-ID: <CADjGqHu2rLLEReGyzBOnVbkvEiz+DCR3fMwjf11ACJGeds1q5A@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2013-03-15 1:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 1:39 TJ Luoma [this message]
2013-03-15 1:55 ` Alex Satrapa
2013-03-15 3:19 ` TJ Luoma
2013-03-15 5:08 ` Phil Pennock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADjGqHu2rLLEReGyzBOnVbkvEiz+DCR3fMwjf11ACJGeds1q5A@mail.gmail.com \
--to=luomat@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).