`sed: -e expression #1, char 4: unknown command:` but the line endings are fine

You have syntactic error. There can't be any space after -i, just the extension; this is the source of the (initial) error message.

Also, to remove a line based on a pattern you need /<pattern>/ d with sed (there are other approaches but this one is the cleanest). So do:

sed -i".bak" '/set -x/ d' "$(which tsc)"

Optionally, as the backup extension does not contain any whitespace or control characters, you could get away without quoting in this case:

sed -i.bak '/set -x/ d' "$(which tsc)"

Tags:

Shell

Sed