Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
trying to create a "|| failed" function
- X-seq: zsh-users 17700
- From: TJ Luoma <luomat@xxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: trying to create a "|| failed" function
- Date: Thu, 14 Mar 2013 21:39:11 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=Osvcih6Q4QCjZVnmU+fsTUAqErD8MeEk+G7AJgjvwK0=; b=S6DaENdpwWYKoRh4/eN8l2B9u92XCa67VeR9AGDEmrAgmUqfwSQlDbOZlmN9rz8Pv6 isezEtiX287ONGkDNOkL6XXBiPMTD9XTi7t20Buau3ElQylIeLafmwzesqw5irwrgjQA 15VtZHbRBSZ4Jcokz4iHAMfP8hLa3SpwpRaETxrrS2CN85pA1JD1qZJ+4h2t+lwFQsEH nY5jup1hBz6GDzmerLITfgYm6wgRUR3AztdiFv8Dw2/ZuIwUIPw5uy3ZyQtl+z6nPnHR GYXo9g8XnZORDk6dREU5Ne3QgHOWXBRrg16ep3ea4G1Lbu9CHE+d9r1u0+d99cZ0EyuR wG9Q==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author