Collin Funk <collin.fu...@gmail.com> writes: > However, that means that when POSIXLY_CORRECT is not defined the exit > status is ambiguous as shown in the following example: > > # Input with a cycle. > $ printf 'a b\nb a\n' | ./src/tsort > tsort: -: input contains a loop: > tsort: a > tsort: b > a > b > $ echo $? > 1 > # Program error. > $ echo 'a a' | ./src/tsort > /dev/full > tsort: write error: No space left on device > $ echo $? > 1
Oops, slight mistake in that example. Pretend that './src/tail' was given the -w argument. The output and exit status will be the same. Here it is run with POSIXLY_CORRECT set: $ printf 'a b\nb a\n' | POSIXLY_CORRECT=1 ./src/tsort -w tsort: -: input contains a loop: tsort: a tsort: b a b $ echo $? 1 $ echo 'a a' | POSIXLY_CORRECT=1 ./src/tsort > /dev/full tsort: write error: No space left on device $ echo $? 125 We can use the exit value to determine the number of cycles (0 - 124) or an error (125) in this case. Collin