I have the following bash file called "file" (the real one does something useful):
ed db/seeds.rb <<EOF
1,$-1d
a
123
456
.
w
q
EOF
When I run "bash file" it doesn't delete any lines. If I use 1d
instead of 1,$-1d
it does delete the first line.
Why doesn't this work? I could easily do a workaround, but I'm curious why this doesn't work.
expect
or similar, the interactive portions can't be scripted in shell script.ed file <<EOF
The script runs the command ("ed" in this case) such that the command thinks the following lines are inputed interactively. This continues until it encounters a line contained only the text following the<<
(EOF in this case). I use this feature all the time.tail
is a dedicated tool for this task.diff -e
produces aned
script to convert file1 to file2.ed
has supported non-interactive use since day 1, in the 1970s.