From: Seb <sbb@tuxfamily.org>
To: dash@vger.kernel.org
Subject: Re: exec command and error checking
Date: Tue, 28 Jan 2014 15:42:46 +0100 [thread overview]
Message-ID: <20140128154246.88cce1619f1cb3bdff457930@tuxfamily.org> (raw)
In-Reply-To: <20140128140523.GB17217@hal.lan>
Le Tue, 28 Jan 2014 15:05:23 +0100
Guido Berhoerster a écrit:
> > [...]
> > if ( exec 9<no_such_file ) 2>/dev/null; then
> > exec 9<no_such_file
> > else
> > echo TEST
> > fi
>
> That's generally a bad idea since it is racy, if no_such_file is
> removeded in between the test and actual exec your script will
> still exit.
In this case, it will break however, so an half-solution is still
better than no solution at all. Plus you can never be sure a file
will remain available for the life-time of a program, especially in
shell where it must often be accessed by a sequency of different
executables. In this regard, shell progamming is mostly racy, and
the best you can do is to ensure the target exists before dealing
with it, isn't it?
> Also, do no use test -a if you care about portability,
> it's an XSI extension and marked obsolescent.
Indeed. Thanks for pointing this. :)
++
Seb.
next prev parent reply other threads:[~2014-01-28 14:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-28 12:16 exec command and error checking Марк Коренберг
2014-01-28 13:17 ` Guido Berhoerster
2014-01-28 15:32 ` Paul Gilmartin
2014-01-28 21:59 ` Jilles Tjoelker
2014-01-28 23:18 ` Guido Berhoerster
2014-01-29 3:19 ` Chet Ramey
2014-01-28 13:40 ` Seb
2014-01-28 14:05 ` Guido Berhoerster
2014-01-28 14:42 ` Seb [this message]
2014-01-28 14:52 ` Paul Gilmartin
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=20140128154246.88cce1619f1cb3bdff457930@tuxfamily.org \
--to=sbb@tuxfamily.org \
--cc=dash@vger.kernel.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.
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).