Re: exec command and error checking

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

 



Le Tue, 28 Jan 2014 18:16:23 +0600
Марк Коренберг a écrit:

> $ exec 9<no_such_file && echo TEST
> dash: 1: cannot open no_such_file: No such file

As previously said, POSIX specifies that the built-in redirection
errors cause the shell to exit. See:

  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_20
  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_01
  
> $ exec 9<no_such_file || echo TEST
> dash: 2: cannot open no_such_file: No such file
> 
> 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

++
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