5.7. Error Messages and Exit Status

 <  Day Day Up  >  

When sed encounters a syntax error, it sends a pretty straightforward error message to standard error, but if it cannot figure out what you did wrong, sed gets "garbled," which we could guess means confused . If the syntax is error-free, the exit status that sed returns to the shell is a zero for success and a nonzero integer for failure. [2]

[2] For a complete list of diagnostics, see the man page for sed .

Example 5.7.
 1   %  sed '1,3v ' file   sed: Unrecognized command: 1,3v  %  echo $status   # use   echo $?   if using Korn or Bourne shell   2  2   %  sed '/^John' file   sed: Illegal or missing delimiter: /^John  3   %  sed 's/134345/g' file   sed: Ending delimiter missing on substitution: s/134345/g  

EXPLANATION

  1. The v command is unrecognized by sed . The exit status was 2, indicating that sed exited with a syntax problem.

  2. The pattern /^John is missing the closing forward slash.

  3. The substitution command, s , contains the search string but not the replacement string.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net