use newer shell features (suitable for bash / Korn / Posix)

changes:
  (1) backticks replaced by  $(....)
  (2) sed delimiters changed to pipe, eliminating the need to escape backslashes
  (3) replace escaped double quoutes (inside double quotes),
      replaced them with single quotes without impacting variable interpolation
  (4) use of "==" for coparison instead of "="