Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question
1  
looks like typical line ending confusion. Did you edit it with a Windows editor? –  wurtel Feb 18 at 13:37
    
so this script works just fine for me: bash script.sh –  Dārayavahuš tdi Feb 18 at 13:42

1 Answer 1

up vote 0 down vote accepted

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
share|improve this answer
1  
is your editor translating tabs to spacres? <<- only works on actual tabs –  Dani_l Feb 18 at 14:56
    
It is yes but for this script I decided to leave out tabs all together –  Trent Feb 18 at 15:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.