2

This is related to a question I asked earlier but I would like to keep it separate in case anyone else can find use in it.

I have a command that I am running on a file called dummy.out from the command line which is as followed

vim -E -s dummy.out <<-EOF
   :%s/old/new/g
   :%s/old2/new2/g
   :%s/old3/new3/g
   :update
   :quit
EOF

from the command line this is working but when I add it to my bash file bashscript.sh

#!/bin/bash
# bash script

var01="start script"
echo $var01

vim -E -s dummy.out <<-EOF
   :%s/old/new/g
   :%s/old2/new2/g
   :%s/old3/new3/g
   :update
   :quit
EOF

I get the following error

warning: here-document at line 7 delimited by end-of-file (wanted 'EOF')

How would I get this command line command to run inside this bash file?

2
  • 1
    looks like typical line ending confusion. Did you edit it with a Windows editor?
    – wurtel
    Feb 18, 2015 at 13:37
  • so this script works just fine for me: bash script.sh
    – Darek
    Feb 18, 2015 at 13:42

1 Answer 1

1

Ok it looks like the EOF was just a lot more sensitive than I excpected

this doesn't work

vim -E -s dummy.out <<-EOF
   :%s/old/new/g
   :%s/old2/new2/g
   :%s/old3/new3/g
   :update
   :quit
EOF

this does

vim -E -s dummy.out << EOF
:%s/old/new/g
:%s/old2/new2/g
:%s/old3/new3/g
:update
:quit
EOF
2
  • 1
    is your editor translating tabs to spacres? <<- only works on actual tabs
    – Dani_l
    Feb 18, 2015 at 14:56
  • It is yes but for this script I decided to leave out tabs all together Feb 18, 2015 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .