4.6. Error Messages and Exit Status

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 you could guess means confused. The exit status that sed returns to the shell, if its syntax is error-free, is a zero for success and a nonzero integer for failure. [2]

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

Example 4.4.
1 % sed '1,3v ' file
					sed: -e expression #1, char 4: Unknown command: ''v''

  % echo $status
					(echo $? if using sh or ksh shells)
  2

2 % sed '/John' file
					sed: -e expression #1, char 5: Unterminated address regex

3 % sed 's/1235/g' file
					sed: -e expression #1, char 7: Unterminated 's' command ...

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.