I want to insert a big chunk of code using a bash script.
This is how I got it to work using sed(1);
$ sed "/);/i\
\ \ \ \ 'doctrine' => array(\n\
'driver' => array(\n\
__NAMESPACE__ . '_driver' => array(\n\
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',\n\
'cache' => 'array',\n\
'paths' => array(__DIR__ . '\../src/' . __NAMESPACE__ . '/Entity')\n\
),\n\
'orm_default' => array(\n\
'drivers' => array(\n\
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'\n\
)\n\
)\n\
)\n\
),\n
" config/autoload/local.php;
Note: I had to add \n and \ at the end of each line in order to make it work.
Is there a way to “not” have to do that? To insert plain text? Perhaps a different command?
Edit: my question is how to insert the text without having to add all the backslashes and newlines.
This is the text I need to insert:
'doctrine' => array( 'driver' => array( __NAMESPACE__ . '_driver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity') ), 'orm_default' => array( 'drivers' => array( __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver' ) ) ) )
Here’s one way:
If you’re trying to insert a file, try: