Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed patch file in sh file

Tags:

patch

I'm trying to create a .sh file which internally runs a patch. So instead of running patch -p0 of a patch file adjacent to the script, I'd like the patch to be embedded within.

I tried the below

patch -p0 <<EOF
Index: app/code/Magento/CustomerImportExport/Model/Import/Customer.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/code/Magento/CustomerImportExport/Model/Import/Customer.php     (date 1487543450000)
+++ app/code/Magento/CustomerImportExport/Model/Import/Customer.php     (revision )
@@ -371,6 +371,7 @@
         // attribute values
         foreach (array_intersect_key($rowData, $this->_attributes) as $attributeCode => $value) {
             if ($newCustomer && !strlen($value)) {
+                               $entityRow[$attributeCode] = $value;
                 continue;
             }

EOF

But it's not working. However when I run patch -p0 on the original patch file, it works without any problems. Any clues what could be wrong?

Thanks,

like image 807
Krt_Malta Avatar asked Feb 20 '17 20:02

Krt_Malta


1 Answers

Try this suggestion from: Re: [bug-patch] patch 2.6.1 with here document in a shell script

Change the above to this, and it will work better:

patch -p0 <<'EOF'

Without the quotes, your script below expands constructs like $@ in the here script.

like image 108
plushpuffin Avatar answered Oct 04 '22 21:10

plushpuffin