Skip to main content
edited title
Link

sed insert: preserve leading spaces from variableinserted string

Source Link

sed insert: preserve leading spaces from variable

I have a variable (extracted from a diff file result) with leading spaces that I want to insert into a file at a specific line. The variable:

add="     public function add($hardware_id = null)"

But when I insert the line with sed, it doesn't print the leading spaces:

$ sed "50i$add" file
...
public function add($hardware_id = null)
...

How to preserve the leading spaces?