How Do You Troubleshoot the Error “sed: -e expression #1, char 1: unknown command: `””?

Problem scenario
You have a sed command in a script, but you get an error like one of the following:

sed: -e expression #1, char 1: unknown command: '' sed: -e expression #1, char 1: unknown command:"'

How do you troubleshoot this?

Solution
You may need to assign variables like this:

var1=" foo""'"" bar" # Place quotes around any unusual characters (e.g., spaces or punctuation)

Use the escape character:

var2="info \'"

Combine the subvariables into one variable:

compvar=$var1$var2

See this posting if you have any further questions.

Leave a comment

Your email address will not be published. Required fields are marked *