Re: exec command and error checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux