Run a Vim command from a bash script
6,000
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
Related videos on Youtube
Author by
waldemar_enns
Primarily Informix-4GL Programmer, Linux Bash Programmer and Linux Administrator. Dabbler in Java, Python, HTML, PHP and JavaScript. Expert at breaking everything.
Updated on September 18, 2022Comments
-
waldemar_enns over 1 year
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?
-
wurtel about 9 yearslooks like typical line ending confusion. Did you edit it with a Windows editor?
-
Darek about 9 yearsso this script works just fine for me: bash script.sh
-
-
Dani_l about 9 yearsis your editor translating tabs to spacres? <<- only works on actual tabs
-
waldemar_enns about 9 yearsIt is yes but for this script I decided to leave out tabs all together