Re: exec command and error checking

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

 



* Seb <sbb@xxxxxxxxxxxxx> [2014-01-28 14:41]:
> Le Tue, 28 Jan 2014 18:16:23 +0600
> > So, I cannot test this operation without using $?
> 
> You can use the file tests:
> 
>  if [ -f no_such_file -a -r no_such_file ]; then
>    exec 9<no_such_file
>  else
>    echo TEST
>  fi
> 
> or a subshell:
> 
>  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. Also, do no use test -a if you care about portability,
it's an XSI extension and marked obsolescent.
-- 
Guido Berhoerster
--
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